]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed memcpy() on NULL warning
authorYann Collet <cyan@fb.com>
Mon, 29 Oct 2018 20:57:37 +0000 (13:57 -0700)
committerYann Collet <cyan@fb.com>
Mon, 29 Oct 2018 20:57:37 +0000 (13:57 -0700)
memcpy(NULL, src, 0) is undefined behavior.

lib/decompress/zstd_decompress.c

index 2491f4dfb4a4f743b76bed17f77015d38eda9a5c..61826e3af2ec0f2cf230ea93821549fee0ef2d5e 100644 (file)
@@ -508,7 +508,10 @@ static size_t ZSTD_copyRawBlock(void* dst, size_t dstCapacity,
                           const void* src, size_t srcSize)
 {
     DEBUGLOG(5, "ZSTD_copyRawBlock");
-    if (dst == NULL) dstCapacity = 0;  /* better safe than sorry */
+    if (dst == NULL) {
+        if (srcSize == 0) return 0;
+        return ERROR(dstSize_tooSmall);
+    }
     if (srcSize > dstCapacity) return ERROR(dstSize_tooSmall);
     memcpy(dst, src, srcSize);
     return srcSize;