Merge pull request #13113 from sethalves/fix-ktx-asan-warning

avoid misaligned pointer deref in ktx code
This commit is contained in:
Ken Cooke 2018-05-08 08:44:18 -07:00 committed by GitHub
commit 14f4c035ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,13 +46,14 @@ struct GPUKTXPayload {
memcpy(data, &_samplerDesc, sizeof(Sampler::Desc));
data += sizeof(Sampler::Desc);
// We can't copy the bitset in Texture::Usage in a crossplateform manner
// So serialize it manually
*(uint32*)data = _usage._flags.to_ulong();
uint32 usageData = _usage._flags.to_ulong();
memcpy(data, &usageData, sizeof(uint32));
data += sizeof(uint32);
*(TextureUsageType*)data = _usageType;
memcpy(data, &_usageType, sizeof(TextureUsageType));
data += sizeof(TextureUsageType);
return data + PADDING;
@ -77,13 +78,15 @@ struct GPUKTXPayload {
memcpy(&_samplerDesc, data, sizeof(Sampler::Desc));
data += sizeof(Sampler::Desc);
// We can't copy the bitset in Texture::Usage in a crossplateform manner
// So unserialize it manually
_usage = Texture::Usage(*(const uint32*)data);
uint32 usageData;
memcpy(&usageData, data, sizeof(uint32));
_usage = Texture::Usage(usageData);
data += sizeof(uint32);
_usageType = *(const TextureUsageType*)data;
memcpy(&_usageType, data, sizeof(TextureUsageType));
return true;
}
@ -710,4 +713,4 @@ bool Texture::evalTextureFormat(const ktx::Header& header, Element& mipFormat, E
return false;
}
return true;
}
}