From patchwork Wed Nov 23 17:36:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9444009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AB0A360778 for ; Wed, 23 Nov 2016 17:42:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9B9026B39 for ; Wed, 23 Nov 2016 17:42:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8B0E27BE5; Wed, 23 Nov 2016 17:42:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4978526B39 for ; Wed, 23 Nov 2016 17:42:02 +0000 (UTC) Received: from localhost ([::1]:35414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9bYX-00045p-0z for patchwork-qemu-devel@patchwork.kernel.org; Wed, 23 Nov 2016 12:42:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9bTm-0000a1-1A for qemu-devel@nongnu.org; Wed, 23 Nov 2016 12:37:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c9bTj-0001qO-HV for qemu-devel@nongnu.org; Wed, 23 Nov 2016 12:37:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57964) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c9bTj-0001pN-9P for qemu-devel@nongnu.org; Wed, 23 Nov 2016 12:37:03 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 725BC61BB6; Wed, 23 Nov 2016 17:37:02 +0000 (UTC) Received: from red.redhat.com (ovpn-116-185.phx2.redhat.com [10.3.116.185]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uANHawdx005223; Wed, 23 Nov 2016 12:37:01 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 23 Nov 2016 11:36:55 -0600 Message-Id: <1479922617-4400-3-git-send-email-eblake@redhat.com> In-Reply-To: <1479922617-4400-1-git-send-email-eblake@redhat.com> References: <1479922617-4400-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 23 Nov 2016 17:37:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/4] test-qga: Avoid qobject_from_jsonv("%"PRId64) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: programmingkidx@gmail.com, armbru@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The qobject_from_jsonv() function implements a pseudo-printf language for creating a QObject; however, it is hard-coded to only parse a subset of formats understood by -Wformat, and is not a straight synonym to bare printf(). In particular, any use of an int64_t integer works only if the system's definition of PRId64 matches what the parser expects; which works on glibc (%lld or %ld depending on 32- vs. 64-bit) and mingw (%I64d), but not on Mac OS (%qd). Rather than enhance the parser, it is just as easy to use normal printf() for this particular conversion, matching what is done elsewhere in this file [1], which is safe in this instance because the format does not contain any of the problematic differences (bare '%' or the '%s' format). The use of PRId64 for a variable named 'pid' is gross, but it is a sad reality of the 64-bit mingw environment, which mistakenly defines pid_t as a 64-bit type even though getpid() returns 'int' on that platform [2]. Our definition of the QGA GuestExec type defines 'pid' as a 64-bit entity, and we can't tighten it to 'int32' unless the mingw header is fixed. Using 'long long' instead of 'int64_t' just so that we can stick with qobject_from_jsonv("%lld") instead of printf() is not any prettier, since we may have later type churn anyways. [1] see 'git grep -A2 strdup_printf tests/test-qga.c' [2] https://bugzilla.redhat.com/show_bug.cgi?id=1397787 Reported by: G 3 Signed-off-by: Eric Blake --- v2: improve commit message, hoist allocation out of loop --- tests/test-qga.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test-qga.c b/tests/test-qga.c index 40af649..868b02a 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -837,6 +837,7 @@ static void test_qga_guest_exec(gconstpointer fix) int64_t pid, now, exitcode; gsize len; bool exited; + char *cmd; /* exec 'echo foo bar' */ ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" @@ -851,9 +852,10 @@ static void test_qga_guest_exec(gconstpointer fix) /* wait for completion */ now = g_get_monotonic_time(); + cmd = g_strdup_printf("{'execute': 'guest-exec-status'," + " 'arguments': { 'pid': %" PRId64 " } }", pid); do { - ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec-status'," - " 'arguments': { 'pid': %" PRId64 " } }", pid); + ret = qmp_fd(fixture->fd, cmd); g_assert_nonnull(ret); val = qdict_get_qdict(ret, "return"); exited = qdict_get_bool(val, "exited"); @@ -863,6 +865,7 @@ static void test_qga_guest_exec(gconstpointer fix) } while (!exited && g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND); g_assert(exited); + g_free(cmd); /* check stdout */ exitcode = qdict_get_int(val, "exitcode");