From e0f85f2fc8e8868b2623a5344781f269bda7d4ba Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 14 Nov 2020 16:24:36 -0800 Subject: better visual conformance only include on vs2005+ (#947) remove some useless #pragma fix a few minor Visual warnings --- lib/lz4.c | 7 +++---- programs/util.h | 6 +++--- tests/checkFrame.c | 9 --------- tests/frametest.c | 3 +-- tests/fuzzer.c | 20 +++++++++++--------- 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 5c6cf4d..9f5e9bf 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -121,10 +121,9 @@ /*-************************************ * Compiler Options **************************************/ -#ifdef _MSC_VER /* Visual Studio */ -# include -# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ -# pragma warning(disable : 4293) /* disable: C4293: too large shift (32-bits) */ +#if defined(_MSC_VER) && (_MSC_VER >= 1400) /* Visual Studio 2005+ */ +# include /* only present in VS2005+ */ +# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ #endif /* _MSC_VER */ #ifndef LZ4_FORCE_INLINE diff --git a/programs/util.h b/programs/util.h index 2f3d0a8..733c1ca 100644 --- a/programs/util.h +++ b/programs/util.h @@ -594,15 +594,15 @@ UTIL_createFileList(const char** inputNames, unsigned inputNamesNb, for (i=0, pos=0, nbFiles=0; i= bufSize) { while (pos + len >= bufSize) bufSize += LIST_SIZE_INCREASE; buf = (char*)UTIL_realloc(buf, bufSize); if (!buf) return NULL; } assert(pos + len < bufSize); - strncpy(buf + pos, inputNames[i], bufSize - pos); - pos += len + 1; + memcpy(buf + pos, inputNames[i], len); + pos += len; nbFiles++; } else { char* bufend = buf + bufSize; diff --git a/tests/checkFrame.c b/tests/checkFrame.c index f39d2ac..f9a1c14 100644 --- a/tests/checkFrame.c +++ b/tests/checkFrame.c @@ -24,15 +24,6 @@ */ /*-************************************ - * Compiler specific - **************************************/ - #ifdef _MSC_VER /* Visual Studio */ - # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ - # pragma warning(disable : 4146) /* disable: C4146: minus unsigned expression */ - #endif - - - /*-************************************ * Includes **************************************/ #include "util.h" /* U32 */ diff --git a/tests/frametest.c b/tests/frametest.c index 2633c90..241fd5f 100644 --- a/tests/frametest.c +++ b/tests/frametest.c @@ -27,8 +27,7 @@ * Compiler specific **************************************/ #ifdef _MSC_VER /* Visual Studio */ -# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ -# pragma warning(disable : 4146) /* disable: C4146: minus unsigned expression */ +# pragma warning(disable : 26451) /* disable: Arithmetic overflow */ #endif diff --git a/tests/fuzzer.c b/tests/fuzzer.c index ba36621..a824813 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -1097,7 +1097,7 @@ static void FUZ_unitTests(int compressionLevel) { int const dSize = LZ4_decompress_safe(testCompressed, testVerify, cSize, testInputSize); assert(dSize == sampleSize); /* correct size */ { XXH32_hash_t const crcCheck = XXH32(testVerify, (size_t)dSize, 0); - assert(crcCheck == crcOrig); + FUZ_CHECKTEST(crcCheck != crcOrig, "LZ4_decompress_safe decompression corruption"); } } } DISPLAYLEVEL(3, " OK \n"); @@ -1121,7 +1121,7 @@ static void FUZ_unitTests(int compressionLevel) { int const dSize = LZ4_decompress_safe(startInput, testVerify, cSize, sampleSize); assert(dSize == sampleSize); /* correct size */ { XXH64_hash_t const crcCheck = XXH64(testVerify, (size_t)dSize, 0); - assert(crcCheck == crcOrig); + FUZ_CHECKTEST(crcCheck != crcOrig, "LZ4_decompress_safe decompression corruption"); } } } } } DISPLAYLEVEL(3, " OK \n"); @@ -1173,12 +1173,12 @@ static void FUZ_unitTests(int compressionLevel) assert(ctx != NULL); /* ensure init is successful */ /* Check access violation with asan */ - FUZ_CHECKTEST( LZ4_saveDict(&streamingState, NULL, 0) != 0, + FUZ_CHECKTEST( LZ4_saveDict(ctx, NULL, 0) != 0, "LZ4_saveDict() can't save anything into (NULL,0)"); /* Check access violation with asan */ { char tmp_buffer[240] = { 0 }; - FUZ_CHECKTEST( LZ4_saveDict(&streamingState, tmp_buffer, sizeof(tmp_buffer)) != 0, + FUZ_CHECKTEST( LZ4_saveDict(ctx, tmp_buffer, sizeof(tmp_buffer)) != 0, "LZ4_saveDict() can't save anything since compression hasn't started"); } } DISPLAYLEVEL(3, "OK \n"); @@ -1290,12 +1290,12 @@ static void FUZ_unitTests(int compressionLevel) assert(ctx != NULL); /* ensure init is successful */ /* Check access violation with asan */ - FUZ_CHECKTEST( LZ4_saveDictHC(&sHC, NULL, 0) != 0, + FUZ_CHECKTEST( LZ4_saveDictHC(ctx, NULL, 0) != 0, "LZ4_saveDictHC() can't save anything into (NULL,0)"); /* Check access violation with asan */ { char tmp_buffer[240] = { 0 }; - FUZ_CHECKTEST( LZ4_saveDictHC(&sHC, tmp_buffer, sizeof(tmp_buffer)) != 0, + FUZ_CHECKTEST( LZ4_saveDictHC(ctx, tmp_buffer, sizeof(tmp_buffer)) != 0, "LZ4_saveDictHC() can't save anything since compression hasn't started"); } } DISPLAYLEVEL(3, "OK \n"); @@ -1596,7 +1596,7 @@ static void FUZ_unitTests(int compressionLevel) DISPLAYLEVEL(3, "LZ4_compress_HC_destSize : "); /* encode congenerical sequence test for HC compressors */ - { LZ4_streamHC_t sHC; /* statically allocated */ + { LZ4_streamHC_t* const sHC = LZ4_createStreamHC(); int const src_buf_size = 3 MB; int const dst_buf_size = 6 KB; int const payload = 0; @@ -1609,6 +1609,7 @@ static void FUZ_unitTests(int compressionLevel) char* dbuf1 = (char*)malloc(dst_buf_size + 1); char* dbuf2 = (char*)malloc(dst_buf_size + 1); + assert(sHC != NULL); assert(dst_buf_size > dst_max_len); if (!sbuf1 || !sbuf2 || !dbuf1 || !dbuf2) { EXIT_MSG("not enough memory for FUZ_unitTests (destSize)"); @@ -1643,8 +1644,8 @@ static void FUZ_unitTests(int compressionLevel) memset(sbuf2, payload, slen); memset(dbuf2, 0, dlen); dbuf2[dlen] = endchk; - LZ4_resetStreamHC(&sHC, compressionLevel); - dsz2 = LZ4_compress_HC_destSize(&sHC, sbuf2, dbuf2, &srcsz2, dlen, compressionLevel); + LZ4_resetStreamHC(sHC, compressionLevel); + dsz2 = LZ4_compress_HC_destSize(sHC, sbuf2, dbuf2, &srcsz2, dlen, compressionLevel); DISPLAYLEVEL(5, "LZ4_compress_HC_destSize: %i bytes compressed into %i bytes, ", srcsz2, dsz2); DISPLAYLEVEL(5, "last token : 0x%0X, ", dbuf2[dsz2 - 6]); DISPLAYLEVEL(5, "last ML extra lenbyte : 0x%0X, \n", dbuf2[dsz2 - 7]); @@ -1663,6 +1664,7 @@ static void FUZ_unitTests(int compressionLevel) FUZ_CHECKTEST(memcmp(sbuf1, sbuf2, (size_t)res2), "LZ4_compress_HC_destSize() decompression corruption!"); } } + LZ4_freeStreamHC(sHC); free(sbuf1); free(sbuf2); free(dbuf1); -- cgit v0.12 From 99ba44a596d2b86090fa85bf09f9a2642bfd0001 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 14 Nov 2020 17:25:31 -0800 Subject: fixed minor Visual warning doesn't happen on my environment, though it's a different version of Visual Studio --- tests/frametest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/frametest.c b/tests/frametest.c index 241fd5f..e613cbf 100644 --- a/tests/frametest.c +++ b/tests/frametest.c @@ -1060,7 +1060,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi CHECK(op[dstEndSize] != canaryByte, "LZ4F_compressEnd writes beyond dstCapacity !"); if (LZ4F_isError(flushedSize)) { if (tooSmallDstEnd) /* failure is allowed */ continue; - CHECK(1, "Compression completion failed (error %i : %s)", + CHECK(!tooSmallDstEnd, "Compression completion failed (error %i : %s)", (int)flushedSize, LZ4F_getErrorName(flushedSize)); } op += flushedSize; -- cgit v0.12 From f61b034cd7cd16c288db999263a77ab8a0e05610 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 14 Nov 2020 20:39:23 -0800 Subject: fix minor win32 warning --- lib/lz4hc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 8c6063f..77c9f43 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -172,7 +172,8 @@ static unsigned LZ4HC_countPattern(const BYTE* ip, const BYTE* const iEnd, U32 const pattern32) { const BYTE* const iStart = ip; - reg_t const pattern = (sizeof(pattern)==8) ? (reg_t)pattern32 + (((reg_t)pattern32) << 32) : pattern32; + reg_t const pattern = (sizeof(pattern)==8) ? + (reg_t)pattern32 + (((reg_t)pattern32) << (sizeof(pattern)*4)) : pattern32; while (likely(ip < iEnd-(sizeof(pattern)-1))) { reg_t const diff = LZ4_read_ARCH(ip) ^ pattern; -- cgit v0.12