diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-08-03 11:26:48 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-08-10 13:11:27 -0500 |
commit | 22f2e344748370b2e13888ba1057ebea2579970c (patch) | |
tree | 0350148ddbd962a9eeb68097dae6de0da262a9e8 /hw/qdev.c | |
parent | ea2b7271bfb601bf5b57c03a7bc46482e6342b95 (diff) |
fix qdev_print_devinfo()
snprintf returns number of bytes needed for the output, not the number
of bytes actually written. Thus the math is wrong ...
Spotted by Markus Armbruster.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Message-Id:
Diffstat (limited to 'hw/qdev.c')
-rw-r--r-- | hw/qdev.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -108,15 +108,23 @@ DeviceState *qdev_create(BusState *bus, const char *name) static int qdev_print_devinfo(DeviceInfo *info, char *dest, int len) { int pos = 0; + int ret; - pos += snprintf(dest+pos, len-pos, "name \"%s\", bus %s", - info->name, info->bus_info->name); - if (info->alias) - pos += snprintf(dest+pos, len-pos, ", alias \"%s\"", info->alias); - if (info->desc) - pos += snprintf(dest+pos, len-pos, ", desc \"%s\"", info->desc); - if (info->no_user) - pos += snprintf(dest+pos, len-pos, ", no-user"); + ret = snprintf(dest+pos, len-pos, "name \"%s\", bus %s", + info->name, info->bus_info->name); + pos += MIN(len-pos,ret); + if (info->alias) { + ret = snprintf(dest+pos, len-pos, ", alias \"%s\"", info->alias); + pos += MIN(len-pos,ret); + } + if (info->desc) { + ret = snprintf(dest+pos, len-pos, ", desc \"%s\"", info->desc); + pos += MIN(len-pos,ret); + } + if (info->no_user) { + ret = snprintf(dest+pos, len-pos, ", no-user"); + pos += MIN(len-pos,ret); + } return pos; } |