On 03/22/2013 08:19 AM, Wenchao Xia wrote:
>   This allow hmp use this function, just like qemu-img.
> It also returns a pointer now to make it easy to use.
> 

>  
> -void bdrv_image_info_dump(ImageInfo *info)
> +GCC_FMT_ATTR(3, 4)
> +static void snprintf_tail(char **p_buf, int *p_size, const char *fmt, ...)

Yuck.  I'm too worried that you are likely to cause truncation when you
exceed the bounds of the fixed-width buffer.  And you can't argue that
this is here to avoid malloc pressure, since...

>  
> +#define IMAGE_INFO_BUF_SIZE (2048)
>  static void dump_human_image_info_list(ImageInfoList *list)
>  {
>      ImageInfoList *elem;
>      bool delim = false;
> +    char *buf = g_malloc0(IMAGE_INFO_BUF_SIZE);

...you are doing a malloc for the original buffer in the first place.
I'd much rather see use of g_string_append_printf or some similar glib
interface that manages a dynamically-sized output buffer to begin with,
than to attempt to force the output to fit in a fixed-width malloc'd buffer.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to