From 3b917ef6e6e9b18b15f18b6d691c4ea5033cfe41 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 28 Jun 2019 20:55:47 -0700 Subject: travisCI: added ASAN fuzzer tests and fixed minor formatting warnings --- .travis.yml | 6 ++++++ examples/HCStreaming_ringBuffer.c | 9 ++++++--- tests/fullbench.c | 16 +++++++++------- tests/fuzzer.c | 6 +++--- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee643e5..b88d907 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,12 @@ matrix: script: - make -C tests test-frametest test-fuzzer + - name: ASAN tests with fuzzer and frametest + install: + - sudo sysctl -w vm.mmap_min_addr=4096 + script: + - CC=clang MOREFLAGS=-fsanitize=address make -C tests test-frametest test-fuzzer + - name: (Precise) g++ and clang CMake test dist: precise script: diff --git a/examples/HCStreaming_ringBuffer.c b/examples/HCStreaming_ringBuffer.c index a878577..bc8391e 100644 --- a/examples/HCStreaming_ringBuffer.c +++ b/examples/HCStreaming_ringBuffer.c @@ -26,6 +26,7 @@ #include #include #include +#include enum { MESSAGE_MAX_BYTES = 1024, @@ -39,7 +40,8 @@ size_t write_int32(FILE* fp, int32_t i) { } size_t write_bin(FILE* fp, const void* array, int arrayBytes) { - return fwrite(array, 1, arrayBytes, fp); + assert(arrayBytes >= 0); + return fwrite(array, 1, (size_t)arrayBytes, fp); } size_t read_int32(FILE* fp, int32_t* i) { @@ -47,7 +49,8 @@ size_t read_int32(FILE* fp, int32_t* i) { } size_t read_bin(FILE* fp, void* array, int arrayBytes) { - return fread(array, 1, arrayBytes, fp); + assert(arrayBytes >= 0); + return fread(array, 1, (size_t)arrayBytes, fp); } @@ -174,7 +177,7 @@ int main(int argc, const char** argv) return 0; } - if (!strcmp(argv[1], "-p")) pause = 1, fileID = 2; + if (!strcmp(argv[1], "-p")) { pause = 1; fileID = 2; } snprintf(inpFilename, 256, "%s", argv[fileID]); snprintf(lz4Filename, 256, "%s.lz4s-%d", argv[fileID], 9); diff --git a/tests/fullbench.c b/tests/fullbench.c index 4609f13..7d74d3f 100644 --- a/tests/fullbench.c +++ b/tests/fullbench.c @@ -541,9 +541,10 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles) if (initFunction!=NULL) initFunction(); for (chunkNb=0; chunkNb%9i (%5.2f%%),%7.1f MB/s\r", loopNb, compressorName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / bestTime / 1000000); } @@ -586,9 +587,10 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles) } for (chunkNb=0; chunkNb>= 1, nbBits++; + while (v32) { v32 >>= 1; nbBits++; } return nbBits; } @@ -766,8 +766,8 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c if (blockSize > missingBytes) { decodedBuffer[blockSize-missingBytes] = 0; ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize-missingBytes, dict, dictSize); - FUZ_CHECKTEST(ret>=0, "LZ4_decompress_safe_usingDict should have failed : output buffer too small (-%u byte)", missingBytes); - FUZ_CHECKTEST(decodedBuffer[blockSize-missingBytes], "LZ4_decompress_safe_usingDict overrun specified output buffer size (-%u byte) (blockSize=%i)", missingBytes, blockSize); + FUZ_CHECKTEST(ret>=0, "LZ4_decompress_safe_usingDict should have failed : output buffer too small (-%i byte)", missingBytes); + FUZ_CHECKTEST(decodedBuffer[blockSize-missingBytes], "LZ4_decompress_safe_usingDict overrun specified output buffer size (-%i byte) (blockSize=%i)", missingBytes, blockSize); } } /* Compress using external dictionary stream */ -- cgit v0.12