Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MXtop-00026O-Vj for qemu-devel@nongnu.org; Mon, 03 Aug 2009 05:27:00 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MXtol-00025j-I6 for qemu-devel@nongnu.org; Mon, 03 Aug 2009 05:26:59 -0400 Received: from [199.232.76.173] (port=37173 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXtol-00025g-CV for qemu-devel@nongnu.org; Mon, 03 Aug 2009 05:26:55 -0400 Received: from mx2.redhat.com ([66.187.237.31]:43388) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MXtok-0005XF-PZ for qemu-devel@nongnu.org; Mon, 03 Aug 2009 05:26:55 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n739Qsk1001197 for ; Mon, 3 Aug 2009 05:26:54 -0400 From: Gerd Hoffmann Date: Mon, 3 Aug 2009 11:26:48 +0200 Message-Id: <1249291608-14766-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH] fix qdev_print_devinfo() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann 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 --- hw/qdev.c | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 9488dba..fc95115 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -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; } -- 1.6.2.5