From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXxUy-00057H-Hc for qemu-devel@nongnu.org; Thu, 21 Jan 2010 08:55:00 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXxUt-00056M-RW for qemu-devel@nongnu.org; Thu, 21 Jan 2010 08:55:00 -0500 Received: from [199.232.76.173] (port=59554 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXxUs-000565-UL for qemu-devel@nongnu.org; Thu, 21 Jan 2010 08:54:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63678) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXxUs-0008HB-Af for qemu-devel@nongnu.org; Thu, 21 Jan 2010 08:54:54 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0LDsrR3011990 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 21 Jan 2010 08:54:53 -0500 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH v2 6/8] monitor: New argument type 'T' References: <1264003702-17329-1-git-send-email-armbru@redhat.com> <1264003702-17329-7-git-send-email-armbru@redhat.com> <20100121112656.7d702af9@doriath> Date: Thu, 21 Jan 2010 14:54:51 +0100 In-Reply-To: <20100121112656.7d702af9@doriath> (Luiz Capitulino's message of "Thu, 21 Jan 2010 11:26:56 -0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: qemu-devel@nongnu.org Luiz Capitulino writes: > On Wed, 20 Jan 2010 17:08:20 +0100 > Markus Armbruster wrote: > >> This is a double value with optional suffixes ms, us, ns. We'll need >> this to get migrate_set_downtime() QMP-ready. >> >> Signed-off-by: Markus Armbruster >> --- >> monitor.c | 16 +++++++++++++++- >> 1 files changed, 15 insertions(+), 1 deletions(-) >> >> diff --git a/monitor.c b/monitor.c >> index ce97e7b..6dafe0b 100644 >> --- a/monitor.c >> +++ b/monitor.c >> @@ -75,6 +75,9 @@ >> * user mode accepts an optional G, g, M, m, K, k suffix, >> * which multiplies the value by 2^30 for suffixes G and >> * g, 2^20 for M and m, 2^10 for K and k >> + * 'T' double >> + * user mode accepts an optional ms, us, ns suffix, >> + * which divides the value by 1e3, 1e6, 1e9, respectively >> * '/' optional gdb-like print format (like "/10x") >> * >> * '?' optional type (for all types, except '/') >> @@ -3544,6 +3547,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, >> } >> break; >> case 'b': >> + case 'T': >> { >> double val; >> >> @@ -3558,7 +3562,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, >> if (get_double(mon, &val, &p) < 0) { >> goto fail; >> } >> - if (*p) { >> + if (c == 'b' && *p) { >> switch (*p) { >> case 'K': case 'k': >> val *= 1 << 10; p++; break; >> @@ -3568,6 +3572,16 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, >> val *= 1 << 30; p++; break; >> } >> } >> + if (c == 'T' && p[0] && p[1] == 's') { > > Is this indexing of 'p' really correct? What if the value you're interested > is at the of the string? Like: > > .args_type = "str:s,value:b" p points right behind the floating-point number. If no characters follow, it points to the string's terminating zero. If exactly one character follows, it points to that one, and the next one is the terminating zero. If more than one follow, p points to the first one. "p[0] && p[1] == 's'" is safe, because p[0] is safe, and if p[0] != 0, then p[1] is also safe. Convinced? >> + switch (*p) { >> + case 'm': >> + val /= 1e3; p += 2; break; >> + case 'u': >> + val /= 1e6; p += 2; break; >> + case 'n': >> + val /= 1e9; p += 2; break; >> + } >> + } >> if (*p && !qemu_isspace(*p)) { >> monitor_printf(mon, "Unknown unit suffix\n"); >> goto fail;