diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2020-11-15 01:23:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-15 01:23:40 -0800 |
commit | 0bd7dafc93bae758e86260a63a3f1efb4eac1d82 (patch) | |
tree | 5558e50e59d0c201de6e12bc96ad51aa87c05aa3 | |
parent | c1c3d04f1c44ed3d3a37bf7e643e6d542f5311c3 (diff) | |
parent | f61b034cd7cd16c288db999263a77ab8a0e05610 (diff) | |
download | lz4-0bd7dafc93bae758e86260a63a3f1efb4eac1d82.tar.gz lz4-0bd7dafc93bae758e86260a63a3f1efb4eac1d82.tar.bz2 lz4-0bd7dafc93bae758e86260a63a3f1efb4eac1d82.zip |
Merge pull request #953 from lz4/vs2005
better MSVC conformance
-rw-r--r-- | lib/lz4.c | 7 | ||||
-rw-r--r-- | lib/lz4hc.c | 3 | ||||
-rw-r--r-- | programs/util.h | 6 | ||||
-rw-r--r-- | tests/checkFrame.c | 9 | ||||
-rw-r--r-- | tests/frametest.c | 5 | ||||
-rw-r--r-- | tests/fuzzer.c | 20 |
6 files changed, 21 insertions, 29 deletions
@@ -121,10 +121,9 @@ /*-************************************ * Compiler Options **************************************/ -#ifdef _MSC_VER /* Visual Studio */ -# include <intrin.h> -# 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 <intrin.h> /* only present in VS2005+ */ +# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ #endif /* _MSC_VER */ #ifndef LZ4_FORCE_INLINE 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; 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<inputNamesNb; i++) { if (!UTIL_isDirectory(inputNames[i])) { - size_t const len = strlen(inputNames[i]); + size_t const len = strlen(inputNames[i]) + 1; /* include nul char */ if (pos + len >= 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..e613cbf 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 @@ -1061,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; 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); |