qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 1/1 v4] Allow machines to configure the QEMU_VER


From: Peter Maydell
Subject: Re: [Qemu-devel] [PATCH 1/1 v4] Allow machines to configure the QEMU_VERSION that's exposed via hardware
Date: Wed, 23 May 2012 21:54:42 +0100

On 23 May 2012 21:06, Crístian Viana <address@hidden> wrote:
> This would be the new code:
>
> snprintf((void *) w, 12, "QEMU %s", qemu_get_version()); /* char version[12] 
> */
>
> I'm not sure of what value the pointer contains at that moment,
> concatenating doesn't seem safe to me. What if w already contains a string?
> The result won't be the same.

The point is that your snprintf is not actually using the full power of
a format string parser, it's just concatenating two strings ("QEMU "
and the version). The simple way to put two strings into a buffer
one after the other is to copy string A and then concatenate string
B on the end.

> I don't understand the Nokia code, so I prefer
> to leave it as it was before (with snprintf).

The Nokia code as it was before doesn't use sprintf or snprintf.

We're just filling in a buffer in memory, and we have a char[12] array,
as the comment says. (NB that w is an int16_t*, which is why w+=6 moves
us over the array.)

What you want is something like:

   strcpy((void*)w, "QEMU ");
   pstrcat((void*)w, 12, qemu_get_version());

instead of the current single strcpy().

> I don't understand the Nokia code, so I prefer
> to leave it as it was before (with snprintf).

The Nokia code as it was before doesn't use sprintf or snprintf.

-- PMM



reply via email to

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