aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2020-11-14 16:24:36 -0800
committerYann Collet <cyan@fb.com>2020-11-14 16:27:57 -0800
commite0f85f2fc8e8868b2623a5344781f269bda7d4ba (patch)
tree362c2dda28e611c7110c80a4c2ad3d67ae466407
parent468011c346a1e73eede3e70ee8009f812b02cc76 (diff)
downloadlz4-e0f85f2fc8e8868b2623a5344781f269bda7d4ba.tar.gz
better visual conformance
only include <intrin.h> on vs2005+ (#947) remove some useless #pragma fix a few minor Visual warnings
-rw-r--r--lib/lz4.c7
-rw-r--r--programs/util.h6
-rw-r--r--tests/checkFrame.c9
-rw-r--r--tests/frametest.c3
-rw-r--r--tests/fuzzer.c20
5 files changed, 18 insertions, 27 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 5c6cf4dc..9f5e9bfa 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -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/programs/util.h b/programs/util.h
index 2f3d0a82..733c1cad 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 f39d2acf..f9a1c142 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 2633c901..241fd5fb 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 ba36621c..a824813d 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);