Merge pull request #4069 from yandex/fix_ubsan_compression_codecs

Unaligned store of the first element
This commit is contained in:
alexey-milovidov 2019-01-16 00:50:39 +03:00 committed by GitHub
commit 63b0e8924c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,7 +47,7 @@ void compressDataForType(const char * source, UInt32 source_size, char * dest)
auto * dest_with_type = reinterpret_cast<T *>(dest);
if (source_size > 0)
dest_with_type[0] = source_with_type[0];
unalignedStore<T>(&dest_with_type[0], source_with_type[0]);
for (size_t dest_index = 1, dest_end = source_size / sizeof(T); dest_index < dest_end; ++dest_index)
unalignedStore<T>(&dest_with_type[dest_index], source_with_type[dest_index] - source_with_type[dest_index - 1]);
@ -63,7 +63,7 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest)
auto * dest_with_type = reinterpret_cast<T *>(dest);
if (source_size > 0)
dest_with_type[0] = source_with_type[0];
unalignedStore<T>(&dest_with_type[0], source_with_type[0]);
for (size_t dest_index = 1, dest_end = source_size / sizeof(T); dest_index < dest_end; ++dest_index)
unalignedStore<T>(&dest_with_type[dest_index], source_with_type[dest_index] + dest_with_type[dest_index - 1]);