* [Qemu-devel] [PATCH] usb-bus: use snprintf
@ 2011-01-23 8:48 Blue Swirl
2011-01-24 16:32 ` [Qemu-devel] " Gerd Hoffmann
0 siblings, 1 reply; 2+ messages in thread
From: Blue Swirl @ 2011-01-23 8:48 UTC (permalink / raw)
To: Gerd Hoffmann, qemu-devel
Avoid this warning from OpenBSD linker:
LINK i386-softmmu/qemu
../usb-bus.o(.text+0x27c): In function `usb_get_fw_dev_path':
/src/qemu/hw/usb-bus.c:294: warning: sprintf() is often misused,
please use snprintf()
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
hw/usb-bus.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 6e2e5fd..7aba9bb 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -282,20 +282,22 @@ static char *usb_get_fw_dev_path(DeviceState *qdev)
{
USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
char *fw_path, *in;
- int pos = 0;
+ ssize_t pos = 0, fw_len;
long nr;
- fw_path = qemu_malloc(32 + strlen(dev->port->path) * 6);
+ fw_len = 32 + strlen(dev->port->path) * 6;
+ fw_path = qemu_malloc(fw_len);
in = dev->port->path;
- while (true) {
+ while (fw_len - pos > 0) {
nr = strtol(in, &in, 10);
if (in[0] == '.') {
/* some hub between root port and device */
- pos += sprintf(fw_path + pos, "hub@%ld/", nr);
+ pos += snprintf(fw_path + pos, fw_len - pos, "hub@%ld/", nr);
in++;
} else {
/* the device itself */
- pos += sprintf(fw_path + pos, "%s@%ld", qdev_fw_name(qdev), nr);
+ pos += snprintf(fw_path + pos, fw_len - pos, "%s@%ld",
+ qdev_fw_name(qdev), nr);
break;
}
}
--
1.6.2.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Qemu-devel] Re: [PATCH] usb-bus: use snprintf
2011-01-23 8:48 [Qemu-devel] [PATCH] usb-bus: use snprintf Blue Swirl
@ 2011-01-24 16:32 ` Gerd Hoffmann
0 siblings, 0 replies; 2+ messages in thread
From: Gerd Hoffmann @ 2011-01-24 16:32 UTC (permalink / raw)
To: Blue Swirl; +Cc: qemu-devel
On 01/23/11 09:48, Blue Swirl wrote:
> Avoid this warning from OpenBSD linker:
> LINK i386-softmmu/qemu
> ../usb-bus.o(.text+0x27c): In function `usb_get_fw_dev_path':
> /src/qemu/hw/usb-bus.c:294: warning: sprintf() is often misused,
> please use snprintf()
added to usb patch queue
thanks,
Gerd
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-01-24 16:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-23 8:48 [Qemu-devel] [PATCH] usb-bus: use snprintf Blue Swirl
2011-01-24 16:32 ` [Qemu-devel] " Gerd Hoffmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.