qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] coverity: Model g_memdup()
Date: Tue, 1 Dec 2015 10:32:53 +0100	[thread overview]
Message-ID: <565D6945.2060209@redhat.com> (raw)
In-Reply-To: <1448901152-11716-1-git-send-email-armbru@redhat.com>

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>

      reply	other threads:[~2015-12-01  9:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-30 16:32 [Qemu-devel] [PATCH] coverity: Model g_memdup() Markus Armbruster
2015-12-01  9:32 ` Paolo Bonzini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=565D6945.2060209@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).