]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Don't call wmemmove if size is zero.
authorJoerg Sonnenberger <joerg@bec.de>
Tue, 1 Aug 2017 15:17:45 +0000 (17:17 +0200)
committerJoerg Sonnenberger <joerg@bec.de>
Tue, 1 Aug 2017 15:17:45 +0000 (17:17 +0200)
The data pointers can be NULL in this case and ISO C says this is UB.

libarchive/archive_string.c

index 5ae09b626cbcf9ecad0ab98960e3f689c5c1f951..392cc1103f36dd56651b8b7406f3521b504a19b1 100644 (file)
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33
  * without incurring additional memory allocations.
  */
 
+#include <assert.h>
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
@@ -214,7 +215,9 @@ archive_wstring_append(struct archive_wstring *as, const wchar_t *p, size_t s)
 {
        if (archive_wstring_ensure(as, as->length + s + 1) == NULL)
                return (NULL);
-       wmemmove(as->s + as->length, p, s);
+       assert(p != NULL);
+       if (s)
+               wmemmove(as->s + as->length, p, s);
        as->length += s;
        as->s[as->length] = 0;
        return (as);