qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v3 3/6] vmdk: Clean up descriptor file reading


From: Don Koch
Subject: Re: [Qemu-devel] [PATCH v3 3/6] vmdk: Clean up descriptor file reading
Date: Wed, 3 Dec 2014 12:09:14 -0500

On Wed, 3 Dec 2014 18:28:38 +0800
Fam Zheng <address@hidden> wrote:

> Zeroing a buffer that will be filled right after is not necessary, and
> allocating a power of two + 1 is naughty.
> 
> Suggested-by: Markus Armbruster <address@hidden>
> Signed-off-by: Fam Zheng <address@hidden>
> ---

Reviewed-by: Don Koch <address@hidden>

>  block/vmdk.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 28d22db..82257cd 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -557,8 +557,8 @@ static char *vmdk_read_desc(BlockDriverState *file, 
> uint64_t desc_offset,
>          return NULL;
>      }
>  
> -    size = MIN(size, 1 << 20);  /* avoid unbounded allocation */
> -    buf = g_malloc0(size + 1);
> +    size = MIN(size, (1 << 20) - 1);  /* avoid unbounded allocation */
> +    buf = g_malloc(size + 1);
>  
>      ret = bdrv_pread(file, desc_offset, buf, size);
>      if (ret < 0) {
> @@ -566,6 +566,7 @@ static char *vmdk_read_desc(BlockDriverState *file, 
> uint64_t desc_offset,
>          g_free(buf);
>          return NULL;
>      }
> +    buf[ret] = 0;
>  
>      return buf;
>  }
> -- 
> 1.9.3
> 
> 



reply via email to

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