Message ID | 15FC42E2-5823-4AF4-A945-0F7C60E7751C@fb.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Jul 11, 2017 at 06:01:38AM +0000, Nick Terrell wrote: > On 7/10/17, 9:57 PM, "Nick Terrell" <terrelln@fb.com> wrote: > > The problem is caused by a gcc-7 bug [1]. It miscompiles > > ZSTD_wildcopy(void *dst, void const *src, ptrdiff_t len) when len is 0. > > Sorry, my patch still triggered the gcc bug, I used the wrong compiler. > This patch works, and runs about the same speed as before the patch for > small inputs, and slightly faster for larger inputs (100+ bytes). I'll > look for a faster workaround if benchmarks show it matters. Confirmed, the fix stops the crash for me. Yay! > --- a/lib/zstd/zstd_internal.h > +++ b/lib/zstd/zstd_internal.h > @@ -139,12 +139,8 @@ static void ZSTD_copy8(void *dst, const void *src) { memcpy(dst, src, 8); } > #define WILDCOPY_OVERLENGTH 8 > ZSTD_STATIC void ZSTD_wildcopy(void *dst, const void *src, ptrdiff_t length) > { > - const BYTE *ip = (const BYTE *)src; > - BYTE *op = (BYTE *)dst; > - BYTE *const oend = op + length; > - do > - COPY8(op, ip) > - while (op < oend); > + if (length > 0) > + memcpy(dst, src, length); > } > > ZSTD_STATIC void ZSTD_wildcopy_e(void *dst, const void *src, void *dstEnd) /* should be faster for decoding, but strangely, not verified on all platform */
diff --git a/lib/zstd/zstd_internal.h b/lib/zstd/zstd_internal.h index 6748719..ade0365 100644 --- a/lib/zstd/zstd_internal.h +++ b/lib/zstd/zstd_internal.h @@ -126,7 +126,9 @@ static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG; /*-******************************************* * Shared functions to include for inlining *********************************************/ -static void ZSTD_copy8(void *dst, const void *src) { memcpy(dst, src, 8); } +static void ZSTD_copy8(void *dst, const void *src) { + ZSTD_write64(dst, ZSTD_read64(src)); +} #define COPY8(d, s) \ { \ ZSTD_copy8(d, s); \