Received: from eggs.gnu.org ([208.118.235.92]:51060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUHSz-0006jN-R7 for qemu-devel@nongnu.org; Tue, 15 May 2012 09:07:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SUHSu-0006YE-7L for qemu-devel@nongnu.org; Tue, 15 May 2012 09:07:05 -0400 Received: from mx.meyering.net ([88.168.87.75]:59204 helo=hx.meyering.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUHSt-0006Xk-Sh for qemu-devel@nongnu.org; Tue, 15 May 2012 09:07:00 -0400 From: jim@meyering.net Date: Tue, 15 May 2012 15:04:37 +0200 Message-Id: <1337087078-24056-3-git-send-email-jim@meyering.net> In-Reply-To: <1337087078-24056-1-git-send-email-jim@meyering.net> References: <1337087078-24056-1-git-send-email-jim@meyering.net> Subject: [Qemu-devel] [PATCH 2/3] scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Maydell , Anthony Liguori , Stefan Hajnoczi , "Michael S. Tsirkin" , Jim Meyering , Markus Armbruster , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Avi Kivity , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Floris Bos , Richard Henderson From: Jim Meyering Use g_strdup rather than strdup, because the sole caller (qdev_get_fw_dev_path_helper) assumes it gets non-NULL, and dereferences it. Besides, in that caller, the allocated buffer is already freed with g_free, so it's better to allocate with a matching g_strdup. In one case, (scsi-bus.c) it was trivial, so I replaced an snprintf+ g_strdup combination with an equivalent g_strdup_printf use. Signed-off-by: Jim Meyering --- hw/ide/qdev.c | 2 +- hw/isa-bus.c | 2 +- hw/pci.c | 2 +- hw/qdev.c | 2 +- hw/scsi-bus.c | 8 ++------ hw/sysbus.c | 2 +- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index a46578d..9edfd8b 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -50,7 +50,7 @@ static char *idebus_get_fw_dev_path(DeviceState *dev) snprintf(path, sizeof(path), "%s@%d", qdev_fw_name(dev), ((IDEBus*)dev->parent_bus)->bus_id); - return strdup(path); + return g_strdup(path); } static int ide_qdev_init(DeviceState *qdev) diff --git a/hw/isa-bus.c b/hw/isa-bus.c index 5a43f03..822b040 100644 --- a/hw/isa-bus.c +++ b/hw/isa-bus.c @@ -227,7 +227,7 @@ static char *isabus_get_fw_dev_path(DeviceState *dev) snprintf(path + off, sizeof(path) - off, "@%04x", d->ioport_id); } - return strdup(path); + return g_strdup(path); } MemoryRegion *isa_address_space(ISADevice *dev) diff --git a/hw/pci.c b/hw/pci.c index b706e69..dc21631 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1898,7 +1898,7 @@ static char *pcibus_get_fw_dev_path(DeviceState *dev) PCI_SLOT(d->devfn)); if (PCI_FUNC(d->devfn)) snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn)); - return strdup(path); + return g_strdup(path); } static char *pcibus_get_dev_path(DeviceState *dev) diff --git a/hw/qdev.c b/hw/qdev.c index 6a8f6bd..ab299cf 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -512,7 +512,7 @@ char* qdev_get_fw_dev_path(DeviceState *dev) path[l-1] = '\0'; - return strdup(path); + return g_strdup(path); } static char *qdev_get_type(Object *obj, Error **errp) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 8ab9bcd..a4e93d1 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1470,12 +1470,8 @@ static char *scsibus_get_dev_path(DeviceState *dev) static char *scsibus_get_fw_dev_path(DeviceState *dev) { SCSIDevice *d = SCSI_DEVICE(dev); - char path[100]; - - snprintf(path, sizeof(path), "channel@%x/%s@%x,%x", d->channel, - qdev_fw_name(dev), d->id, d->lun); - - return strdup(path); + return g_strdup_printf("channel@%x/%s@%x,%x", d->channel, + qdev_fw_name(dev), d->id, d->lun); } SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun) diff --git a/hw/sysbus.c b/hw/sysbus.c index db4efcc..8a9b85d 100644 --- a/hw/sysbus.c +++ b/hw/sysbus.c @@ -203,7 +203,7 @@ static char *sysbus_get_fw_dev_path(DeviceState *dev) snprintf(path + off, sizeof(path) - off, "@i%04x", s->pio[0]); } - return strdup(path); + return g_strdup(path); } void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr, -- 1.7.10.2.484.gcd07cc5