summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--lib/lz4.h8
-rw-r--r--tests/frametest.c26
-rw-r--r--tests/fuzzer.c16
4 files changed, 28 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index e92ae8d..3f1b414 100644
--- a/Makefile
+++ b/Makefile
@@ -91,9 +91,12 @@ travis-install:
test:
$(MAKE) -C $(TESTDIR) test
+clangtest: CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion"
clangtest: clean
clang -v
- CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) all CC=clang
+ @CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(LZ4DIR) all CC=clang
+ @CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(PRGDIR) all CC=clang
+ @CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(TESTDIR) all CC=clang
sanitize: clean
CFLAGS="-O3 -g -fsanitize=undefined" $(MAKE) test CC=clang FUZZER_TIME="-T1mn" NB_LOOPS=-i1
diff --git a/lib/lz4.h b/lib/lz4.h
index 17abd52..d5ac9cb 100644
--- a/lib/lz4.h
+++ b/lib/lz4.h
@@ -1,7 +1,7 @@
/*
- LZ4 - Fast LZ compression algorithm
- Header File
- Copyright (C) 2011-2016, Yann Collet.
+ * LZ4 - Fast LZ compression algorithm
+ * Header File
+ * Copyright (C) 2011-2016, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
@@ -423,7 +423,7 @@ struct LZ4_streamDecode_s {
# elif defined(_MSC_VER)
# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
# else
-# warning "WARNING: You need to implement LZ4_DEPRECATED for this compiler"
+# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler")
# define LZ4_DEPRECATED(message)
# endif
#endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
diff --git a/tests/frametest.c b/tests/frametest.c
index d4afc58..a99728f 100644
--- a/tests/frametest.c
+++ b/tests/frametest.c
@@ -139,10 +139,10 @@ unsigned int FUZ_rand(unsigned int* src)
#define FUZ_RAND15BITS (FUZ_rand(seed) & 0x7FFF)
#define FUZ_RANDLENGTH ( (FUZ_rand(seed) & 3) ? (FUZ_rand(seed) % 15) : (FUZ_rand(seed) % 510) + 15)
-static void FUZ_fillCompressibleNoiseBuffer(void* buffer, unsigned bufferSize, double proba, U32* seed)
+static void FUZ_fillCompressibleNoiseBuffer(void* buffer, size_t bufferSize, double proba, U32* seed)
{
BYTE* BBuffer = (BYTE*)buffer;
- unsigned pos = 0;
+ size_t pos = 0;
U32 P32 = (U32)(32768 * proba);
/* First Byte */
@@ -152,20 +152,18 @@ static void FUZ_fillCompressibleNoiseBuffer(void* buffer, unsigned bufferSize, d
/* Select : Literal (noise) or copy (within 64K) */
if (FUZ_RAND15BITS < P32) {
/* Copy (within 64K) */
- unsigned match, end;
- unsigned length = FUZ_RANDLENGTH + 4;
- unsigned offset = FUZ_RAND15BITS + 1;
- if (offset > pos) offset = pos;
- if (pos + length > bufferSize) length = bufferSize - pos;
- match = pos - offset;
- end = pos + length;
+ size_t const lengthRand = FUZ_RANDLENGTH + 4;
+ size_t const length = MIN(lengthRand, bufferSize - pos);
+ size_t const end = pos + length;
+ size_t const offsetRand = FUZ_RAND15BITS + 1;
+ size_t const offset = MIN(offsetRand, pos);
+ size_t match = pos - offset;
while (pos < end) BBuffer[pos++] = BBuffer[match++];
} else {
/* Literal (noise) */
- unsigned end;
- unsigned length = FUZ_RANDLENGTH;
- if (pos + length > bufferSize) length = bufferSize - pos;
- end = pos + length;
+ size_t const lengthRand = FUZ_RANDLENGTH + 4;
+ size_t const length = MIN(lengthRand, bufferSize - pos);
+ size_t const end = pos + length;
while (pos < end) BBuffer[pos++] = (BYTE)(FUZ_rand(seed) >> 5);
}
}
@@ -606,7 +604,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
/* main fuzzer test loop */
for ( ; (testNb < nbTests) || (clockDuration > FUZ_GetClockSpan(startClock)) ; testNb++) {
U32 randState = coreRand ^ prime1;
- unsigned const srcBits = (FUZ_rand(&randState) % (FUZ_highbit(srcDataLength-1) - 1)) + 1;
+ unsigned const srcBits = (FUZ_rand(&randState) % (FUZ_highbit((U32)(srcDataLength-1)) - 1)) + 1;
size_t const srcSize = (FUZ_rand(&randState) & ((1<<srcBits)-1)) + 1;
size_t const srcStartId = FUZ_rand(&randState) % (srcDataLength - srcSize);
const BYTE* const srcStart = (const BYTE*)srcBuffer + srcStartId;
diff --git a/tests/fuzzer.c b/tests/fuzzer.c
index 4d8d8dd..50f6871 100644
--- a/tests/fuzzer.c
+++ b/tests/fuzzer.c
@@ -375,23 +375,23 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
/* Test compression HC */
FUZ_DISPLAYTEST;
- ret = LZ4_compress_HC(block, compressedBuffer, blockSize, compressedBufferSize, 9);
+ ret = LZ4_compress_HC(block, compressedBuffer, blockSize, (int)compressedBufferSize, 9);
FUZ_CHECKTEST(ret==0, "LZ4_compressHC() failed");
HCcompressedSize = ret;
/* Test compression HC using external state */
FUZ_DISPLAYTEST;
- ret = LZ4_compress_HC_extStateHC(stateLZ4HC, block, compressedBuffer, blockSize, compressedBufferSize, 9);
+ ret = LZ4_compress_HC_extStateHC(stateLZ4HC, block, compressedBuffer, blockSize, (int)compressedBufferSize, 9);
FUZ_CHECKTEST(ret==0, "LZ4_compressHC_withStateHC() failed");
/* Test compression using external state */
FUZ_DISPLAYTEST;
- ret = LZ4_compress_fast_extState(stateLZ4, block, compressedBuffer, blockSize, compressedBufferSize, 9);
+ ret = LZ4_compress_fast_extState(stateLZ4, block, compressedBuffer, blockSize, (int)compressedBufferSize, 9);
FUZ_CHECKTEST(ret==0, "LZ4_compress_withState() failed");
/* Test compression */
FUZ_DISPLAYTEST;
- ret = LZ4_compress_default(block, compressedBuffer, blockSize, compressedBufferSize);
+ ret = LZ4_compress_default(block, compressedBuffer, blockSize, (int)compressedBufferSize);
FUZ_CHECKTEST(ret==0, "LZ4_compress() failed");
compressedSize = ret;
@@ -531,8 +531,8 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
FUZ_DISPLAYTEST;
{ LZ4_stream_t LZ4_stream;
LZ4_resetStream(&LZ4_stream);
- LZ4_compress_fast_continue (&LZ4_stream, dict, compressedBuffer, dictSize, compressedBufferSize, 1); /* Just to fill hash tables */
- blockContinueCompressedSize = LZ4_compress_fast_continue (&LZ4_stream, block, compressedBuffer, blockSize, compressedBufferSize, 1);
+ LZ4_compress_fast_continue (&LZ4_stream, dict, compressedBuffer, dictSize, (int)compressedBufferSize, 1); /* Just to fill hash tables */
+ blockContinueCompressedSize = LZ4_compress_fast_continue (&LZ4_stream, block, compressedBuffer, blockSize, (int)compressedBufferSize, 1);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_continue failed");
}
@@ -561,7 +561,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
dict -= (FUZ_rand(&randState) & 0xF) + 1; /* Separation, so it is an ExtDict */
if (dict < (char*)CNBuffer) dict = (char*)CNBuffer;
LZ4_loadDict(&LZ4dict, dict, dictSize);
- blockContinueCompressedSize = LZ4_compress_fast_continue(&LZ4dict, block, compressedBuffer, blockSize, compressedBufferSize, 1);
+ blockContinueCompressedSize = LZ4_compress_fast_continue(&LZ4dict, block, compressedBuffer, blockSize, (int)compressedBufferSize, 1);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_continue failed");
FUZ_DISPLAYTEST;
@@ -620,7 +620,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
if (dict < (char*)CNBuffer) dict = (char*)CNBuffer;
LZ4_resetStreamHC (&LZ4dictHC, FUZ_rand(&randState) & 0x7);
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
- blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, compressedBufferSize);
+ blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compressHC_continue failed");
FUZ_DISPLAYTEST;