]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix the assertion in readLinesFromFile (#3084)
authorXi Ruoyao <xry111@mengyan1223.wang>
Fri, 4 Mar 2022 19:56:44 +0000 (03:56 +0800)
committerGitHub <noreply@github.com>
Fri, 4 Mar 2022 19:56:44 +0000 (14:56 -0500)
* fix the assertion in readLinesFromFile

When the file is not terminated by endline, readLineFromFile will append
a '\0' for the last line.  In this case pos + lineLength == dstCapacity.

* test: don't print very long text garbage

programs/util.c
tests/playTests.sh

index d69b72a37ca6102d20eb9af80da5a38de007d919..55bcff25afabec75053fdd6757ad4b743d4b4fc5 100644 (file)
@@ -418,7 +418,7 @@ readLinesFromFile(void* dst, size_t dstCapacity,
     while ( !feof(inputFile) ) {
         size_t const lineLength = readLineFromFile(buf+pos, dstCapacity-pos, inputFile);
         if (lineLength == 0) break;
-        assert(pos + lineLength < dstCapacity);
+        assert(pos + lineLength <= dstCapacity); /* '=' for inputFile not terminated with '\n' */
         pos += lineLength;
         ++nbFiles;
     }
index 71e8dc05818e60a65554e055352539ea3217f535..d4271b2f072d74d2f1dbe24d32da12d43ebe4f05 100755 (executable)
@@ -735,11 +735,11 @@ test -f tmp4
 
 println "test : survive the list of files with too long filenames (--filelist=FILE)"
 datagen -g5M > tmp_badList
-zstd -f --filelist=tmp_badList && die "should have failed : file name length is too long"
+zstd -qq -f --filelist=tmp_badList && die "should have failed : file name length is too long"  # printing very long text garbage on console will cause CI failure
 
 println "test : survive a list of files which is text garbage (--filelist=FILE)"
 datagen > tmp_badList
-zstd -f --filelist=tmp_badList && die "should have failed : list is text garbage"
+zstd -qq -f --filelist=tmp_badList && die "should have failed : list is text garbage"  # printing very long text garbage on console will cause CI failure
 
 println "test : survive a list of files which is binary garbage (--filelist=FILE)"
 datagen -P0 -g1M > tmp_badList