diff --git a/.travis.yml b/.travis.yml index 952c526..d0f00c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ compiler: before_install: - sudo apt-get update -qq - - sudo apt-get install -qq asciidoc libarchive-dev liblzma-dev xz-utils + - sudo apt-get install -qq asciidoc cppcheck libarchive-dev liblzma-dev xz-utils script: - autoconf --version diff --git a/src/common.c b/src/common.c index 99e018f..ade5505 100644 --- a/src/common.c +++ b/src/common.c @@ -1,5 +1,6 @@ #include "pixz.h" +#include #include #include @@ -213,7 +214,16 @@ static void read_file_index_make_space(void) { if (expand || gMoved >= gFIBSize) { // malloc more space gStream.avail_out += gFIBSize; gFIBSize *= 2; - gFileIndexBuf = realloc(gFileIndexBuf, gFIBSize); + + uint8_t *new_gFileIndexBuf = realloc(gFileIndexBuf, gFIBSize); + + if (new_gFileIndexBuf == NULL) { + // TODO is recovery possible? does it even make sense? + // @see https://github.com/vasi/pixz/issues/8#issuecomment-134113347 + die("memory re-allocation failure: %s", strerror(errno)); + } else { + gFileIndexBuf = new_gFileIndexBuf; + } } } diff --git a/test/Makefile.am b/test/Makefile.am index 133fd69..6aebb6f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,5 +1,6 @@ TESTS = \ compress-file-permissions.sh \ + cppcheck-src.sh \ single-file-round-trip.sh \ xz-compatibility-c-option.sh diff --git a/test/cppcheck-src.sh b/test/cppcheck-src.sh new file mode 100755 index 0000000..5c77b15 --- /dev/null +++ b/test/cppcheck-src.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if which cppcheck &> /dev/null ; then + cppcheck --error-exitcode=1 $srcdir/../src +else + echo "no cppcheck, skipping test" + exit 77 +fi