[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] usb-bus: use snprintf
From: |
Blue Swirl |
Subject: |
[Qemu-devel] [PATCH] usb-bus: use snprintf |
Date: |
Sun, 23 Jan 2011 08:48:41 +0000 |
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 <address@hidden>
---
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, "address@hidden/", nr);
+ pos += snprintf(fw_path + pos, fw_len - pos, "address@hidden/",
nr);
in++;
} else {
/* the device itself */
- pos += sprintf(fw_path + pos, "address@hidden",
qdev_fw_name(qdev), nr);
+ pos += snprintf(fw_path + pos, fw_len - pos, "address@hidden",
+ qdev_fw_name(qdev), nr);
break;
}
}
--
1.6.2.4
- [Qemu-devel] [PATCH] usb-bus: use snprintf,
Blue Swirl <=