]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix test on windows
authorYann Collet <cyan@fb.com>
Fri, 18 Oct 2019 21:28:34 +0000 (14:28 -0700)
committerYann Collet <cyan@fb.com>
Fri, 18 Oct 2019 21:28:34 +0000 (14:28 -0700)
isDirectory() doesn't work on Windows
if directory name is followed by '/'

programs/util.c
tests/playTests.sh

index dbdd1cee42a06e285ebf07fd68bdad3ab5381ad6..2249e45130dd7abec814d1414d16b704427bf9f1 100644 (file)
@@ -328,7 +328,6 @@ UTIL_createFileList(const char **inputNames, unsigned inputNamesNb,
     unsigned i, nbFiles;
     char* buf = (char*)malloc(LIST_SIZE_INCREASE);
     char* bufend = buf + LIST_SIZE_INCREASE;
-    const char** fileTable;
 
     if (!buf) return NULL;
 
@@ -343,7 +342,7 @@ UTIL_createFileList(const char **inputNames, unsigned inputNamesNb,
                 if (!buf) return NULL;
             }
             if (buf + pos + len < bufend) {
-                memcpy(buf+pos, inputNames[i], len+1);  /* with final \0 */
+                memcpy(buf+pos, inputNames[i], len+1);  /* including final \0 */
                 pos += len + 1;
                 nbFiles++;
             }
@@ -354,20 +353,20 @@ UTIL_createFileList(const char **inputNames, unsigned inputNamesNb,
 
     if (nbFiles == 0) { free(buf); return NULL; }
 
-    fileTable = (const char**)malloc((nbFiles+1) * sizeof(const char*));
-    if (!fileTable) { free(buf); return NULL; }
+    {   const char** const fileTable = (const char**)malloc((nbFiles + 1) * sizeof(*fileTable));
+        if (!fileTable) { free(buf); return NULL; }
 
-    for (i=0, pos=0; i<nbFiles; i++) {
-        fileTable[i] = buf + pos;
-        pos += strlen(fileTable[i]) + 1;
-    }
-
-    if (buf + pos > bufend) { free(buf); free((void*)fileTable); return NULL; }
+        for (i = 0, pos = 0; i < nbFiles; i++) {
+            fileTable[i] = buf + pos;
+            if (buf + pos > bufend) { free(buf); free((void*)fileTable); return NULL; }
+            pos += strlen(fileTable[i]) + 1;
+        }
 
-    *allocatedBuffer = buf;
-    *allocatedNamesNb = nbFiles;
+        *allocatedBuffer = buf;
+        *allocatedNamesNb = nbFiles;
 
-    return fileTable;
+        return fileTable;
+    }
 }
 
 
index f63a7f69e4300f1ef1073aa3cc2beac87a643c77..80f36d52eec96032bc950fe85d4db1dfd4d32b75 100755 (executable)
@@ -240,7 +240,7 @@ rm tmp         # erase source file
 touch tmp.zst  # create destination file
 $ZSTD -f tmp && die "attempt to compress a non existing file"
 test -f tmp.zst  # destination file should still be present
-rm tmp*
+rm -rf tmp*  # may also erase tmp* directory from previous failed run
 
 println "\n===> decompression only tests "
 head -c 1048576 /dev/zero > tmp
@@ -284,7 +284,7 @@ test -f tmpOutDir/tmp1.zst
 test -f tmpOutDir/tmp2.zst
 println "test : decompress multiple files into an output directory, --output-dir-flat"
 mkdir tmpOutDirDecomp
-$ZSTD tmpOutDir/ -r -d --output-dir-flat tmpOutDirDecomp
+$ZSTD tmpOutDir -r -d --output-dir-flat tmpOutDirDecomp
 test -f tmpOutDirDecomp/tmp2
 test -f tmpOutDirDecomp/tmp1
 rm -rf tmp*