[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 45/45] coverity: Model g_memdup()
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 45/45] coverity: Model g_memdup() |
Date: |
Thu, 17 Dec 2015 18:46:41 +0100 |
From: Markus Armbruster <address@hidden>
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 <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
scripts/coverity-model.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/scripts/coverity-model.c b/scripts/coverity-model.c
index bde7411..ee5bf9d 100644
--- a/scripts/coverity-model.c
+++ b/scripts/coverity-model.c
@@ -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
*/
--
2.5.0
- [Qemu-devel] [PULL 43/45] scsi: always call notifier on async cancellation, (continued)
- [Qemu-devel] [PULL 44/45] coverity: Model g_poll(), Paolo Bonzini, 2015/12/17
- [Qemu-devel] [PULL 33/45] exec: make qemu_ram_ptr_length more similar to qemu_get_ram_ptr, Paolo Bonzini, 2015/12/17
- [Qemu-devel] [PULL 36/45] memory: split address_space_read and address_space_write, Paolo Bonzini, 2015/12/17
- [Qemu-devel] [PULL 38/45] memory: inline a few small accessors, Paolo Bonzini, 2015/12/17
- [Qemu-devel] [PULL 39/45] memory: try to inline constant-length reads, Paolo Bonzini, 2015/12/17
- [Qemu-devel] [PULL 42/45] scsi: use scsi_req_cancel_async when purging requests, Paolo Bonzini, 2015/12/17
- [Qemu-devel] [PULL 45/45] coverity: Model g_memdup(),
Paolo Bonzini <=
- Re: [Qemu-devel] [PULL 00/45] KVM, memory, SCSI, qemu_log, Coverity patches for 2015-12-17, Peter Maydell, 2015/12/17