summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Gordon <noel@chromium.org>2022-12-08 02:46:29 +0000
committerCopybara-Service <copybara-worker@google.com>2022-12-07 18:52:11 -0800
commit18d27fa10b237fdfcbd8f0c65c19fe009981a3bc (patch)
tree0d6bd54e4d47a4f1ef0c2bd4042df7faab39b73d
parentd866d41e168ec04545bb17031fa911007a0581f4 (diff)
downloadzlib-18d27fa10b237fdfcbd8f0c65c19fe009981a3bc.tar.gz
[zlib] make insert_string_simd load window data with zmemcpy
Undefined behavior santizer (UBSan) notes that window data loaded using the existing code makes C++ compilers unhappy. C++ Compilers expect data alignment: so loading from an unaligned object is undefined C++ behaviour. Fix this: use zmemcpy to load the window data. All optimizing C++ tested (see bug) output the same instruction sequence, before and after this change. So no change in performance. Bug: 1399295 Test: zlib_bench gzip --compression 6 ~/snappy/testdata/* Change-Id: I90cfd66c803686c3834d88c3bc33833216598836 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4086462 Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org> Commit-Queue: Noel Gordon <noel@chromium.org> Cr-Commit-Position: refs/heads/main@{#1080742} NOKEYCHECK=True GitOrigin-RevId: 36bfeb91012cd6c6897eda645e5375abf14c1c01
-rw-r--r--contrib/optimizations/insert_string.h5
1 files changed, 2 insertions, 3 deletions
diff --git a/contrib/optimizations/insert_string.h b/contrib/optimizations/insert_string.h
index 2a04f69..c6a296a 100644
--- a/contrib/optimizations/insert_string.h
+++ b/contrib/optimizations/insert_string.h
@@ -57,10 +57,9 @@
TARGET_CPU_WITH_CRC
local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) {
Pos ret;
- unsigned *ip, val, h = 0;
+ unsigned val, h = 0;
- ip = (unsigned*)&s->window[str];
- val = *ip;
+ zmemcpy(&val, &s->window[str], sizeof(val));
if (s->level >= 6)
val &= 0xFFFFFF;