]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
coverity: Model g_memdup()
authorMarkus Armbruster <armbru@redhat.com>
Mon, 30 Nov 2015 16:32:32 +0000 (17:32 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 17 Dec 2015 16:33:49 +0000 (17:33 +0100)
We model all the non-deprecated memory allocation functions from
https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html
except for g_memdup(), g_clear_pointer(), g_steal_pointer().  We don't
use the latter two.  Model the former.

Coverity now reports an OVERRUN
vl.c:2317: alloc_strlen: Allocating insufficient memory for the terminating null of the string.
Correct, but we omit the terminating null intentionally there.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1448901152-11716-1-git-send-email-armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
scripts/coverity-model.c

index bde7411094897716ac0dfcf880080cae6de93a95..ee5bf9d078b8b4cedc6c5b8b06bc6b5b55949dcb 100644 (file)
@@ -236,6 +236,23 @@ void *g_try_realloc(void *ptr, size_t size)
     return g_try_realloc_n(ptr, 1, size);
 }
 
+/* Other memory allocation functions */
+
+void *g_memdup(const void *ptr, unsigned size)
+{
+    unsigned char *dup;
+    unsigned i;
+
+    if (!ptr) {
+        return NULL;
+    }
+
+    dup = g_malloc(size);
+    for (i = 0; i < size; i++)
+        dup[i] = ((unsigned char *)ptr)[i];
+    return dup;
+}
+
 /*
  * GLib string allocation functions
  */