qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 1/1] Add qemu_get_counted_string to read a strin


From: Amit Shah
Subject: Re: [Qemu-devel] [PATCH 1/1] Add qemu_get_counted_string to read a string prefixed by a count byte
Date: Wed, 20 May 2015 12:36:50 +0530

On (Fri) 15 May 2015 [16:19:38], Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <address@hidden>
> 
> and use it in loadvm_state and ram_load.
> 
> Where ever it's used, check the return and error if it failed.
> 
> Minor: ram_load was using a 257 byte array for its string, the
>        maximum length is 255 bytes + 0 terminator, so fix to 256
> 
> Signed-off-by: Dr. David Alan Gilbert <address@hidden>

(snip)

> +/*
> + * Get a string whose length is determined by a single preceding byte
> + * A preallocated 256 byte buffer must be passed in.
> + * Returns: len on success and a 0 terminated string in the buffer
> + *          else 0
> + *          (Note a 0 length string will return 0 either way)
> + */
> +size_t qemu_get_counted_string(QEMUFile *f, char buf[256])
> +{
> +    size_t len = qemu_get_byte(f);
> +    size_t res = qemu_get_buffer(f, (uint8_t *)buf, len);
> +
> +    buf[len] = 0;

For safety, let's use

    buf[res] = 0; here...


                Amit



reply via email to

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