* [Qemu-devel] [PATCH] coverity: Model g_memdup()
@ 2015-11-30 16:32 Markus Armbruster
2015-12-01 9:32 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2015-11-30 16:32 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini
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>
---
scripts/coverity-model.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/scripts/coverity-model.c b/scripts/coverity-model.c
index 617f67d..e1d5f45 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.4.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] coverity: Model g_memdup()
2015-11-30 16:32 [Qemu-devel] [PATCH] coverity: Model g_memdup() Markus Armbruster
@ 2015-12-01 9:32 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2015-12-01 9:32 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel
On 30/11/2015 17:32, Markus Armbruster wrote:
> 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>
> ---
> scripts/coverity-model.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/scripts/coverity-model.c b/scripts/coverity-model.c
> index 617f67d..e1d5f45 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
> */
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-01 9:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-30 16:32 [Qemu-devel] [PATCH] coverity: Model g_memdup() Markus Armbruster
2015-12-01 9:32 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.