qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently


From: jcd
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Fri, 29 May 2009 10:28:03 +0100 (GMT+01:00)

Hi Kevin,

Thanks for pointing this. I guess it just sounds strange to me that somebody 
would want to alloc 0 bytes. But why not ...

I guess that if pattern_count/count is set to 0 we can just avoid the all 
processing of malloc/memset/memcmp/free anyway.

Would you be ok with something like:

if (Pflag && pattern_count) {

instead of: 

if (Pflag) {

JC

----- Mail Original -----
De: "Kevin Wolf" <address@hidden>
À: "Jean-Christophe Dubois" <address@hidden>
Cc: address@hidden, "malc" <address@hidden>
Envoyé: Vendredi 29 Mai 2009 10h42:38 GMT +01:00 Amsterdam / Berlin / Berne / 
Rome / Stockholm / Vienne
Objet: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently

Jean-Christophe Dubois schrieb:
> qemu_malloc, qemu_free and friends are not used consistently in the qemu 
> source code.
> 
> This is a first attempt to use these oveloaded functions consistently all 
> over 
> the place instead of the default glibc versions.
> 
> Signed-off-by: Jean-Christophe DUBOIS <address@hidden>

[...]

> diff -rNu qemu.org/qemu-io.c qemu/qemu-io.c
> --- qemu.org/qemu-io.c        2009-05-16 17:57:27.000000000 +0200
> +++ qemu/qemu-io.c    2009-05-18 23:48:23.000000000 +0200
> @@ -311,14 +311,14 @@
>       }
>  
>       if (Pflag) {
> -             void* cmp_buf = malloc(pattern_count);
> +             void* cmp_buf = qemu_malloc(pattern_count);
>               memset(cmp_buf, pattern, pattern_count);
>               if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {
>                       printf("Pattern verification failed at offset %lld, "
>                               "%d bytes\n",
>                               (long long) offset + pattern_offset, 
> pattern_count);
>               }
> -             free(cmp_buf);
> +             qemu_free(cmp_buf);
>       }
>  
>       if (qflag)
> @@ -465,14 +465,14 @@
>       }
>  
>       if (Pflag) {
> -             void* cmp_buf = malloc(count);
> +             void* cmp_buf = qemu_malloc(count);
>               memset(cmp_buf, pattern, count);
>               if (memcmp(buf, cmp_buf, count)) {
>                       printf("Pattern verification failed at offset %lld, "
>                               "%d bytes\n",
>                               (long long) offset, count);
>               }
> -             free(cmp_buf);
> +             qemu_free(cmp_buf);
>       }
>  
>       if (qflag)

Since recently qemu_malloc behaves differently from malloc with size =
0. This isn't allowed any more with qemu_malloc. So you need to check
for pattern_count == 0 and either print an error message or malloc a
different size, e.g. 1. I'm sure we don't want qemu-io to abort() in
such a case.

Or we could start over with a lengthy discussion about fixing qemu_malloc...

Kevin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]