From patchwork Mon Aug 3 09:26:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 30487 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 645D0B7063 for ; Mon, 3 Aug 2009 19:27:49 +1000 (EST) Received: from localhost ([127.0.0.1]:53092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXtpX-00026d-Mw for incoming@patchwork.ozlabs.org; Mon, 03 Aug 2009 05:27:43 -0400 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 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n739Qrr4021904; Mon, 3 Aug 2009 05:26:53 -0400 Received: from zweiblum.home.kraxel.org (vpn2-8-59.ams2.redhat.com [10.36.8.59]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with SMTP id n739QpKe006262; Mon, 3 Aug 2009 05:26:52 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id CC544700D0; Mon, 3 Aug 2009 11:26:49 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 3 Aug 2009 11:26:48 +0200 Message-Id: <1249291608-14766-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH] fix qdev_print_devinfo() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }