From patchwork Wed Apr 15 11:59:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 461500 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 210F01401AB for ; Wed, 15 Apr 2015 22:01:22 +1000 (AEST) Received: from localhost ([::1]:60117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiM0N-0008P1-Hj for incoming@patchwork.ozlabs.org; Wed, 15 Apr 2015 08:01:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiLzM-0007Rz-Og for qemu-devel@nongnu.org; Wed, 15 Apr 2015 08:00:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YiLzG-0007Bi-OT for qemu-devel@nongnu.org; Wed, 15 Apr 2015 08:00:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiLzG-00079e-ID for qemu-devel@nongnu.org; Wed, 15 Apr 2015 08:00:10 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3FC05SA024211 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 15 Apr 2015 08:00:08 -0400 Received: from localhost (ovpn-113-74.phx2.redhat.com [10.3.113.74]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3FC03Gk028241; Wed, 15 Apr 2015 08:00:03 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 15 Apr 2015 08:59:56 -0300 Message-Id: <1429099196-8635-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Gerd Hoffmann Subject: [Qemu-devel] [PATCH v2] qemu-config: Accept empty option values X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently it is impossible to set an option in a config file to an empty string, because the parser matches only lines containing non-empty strings between double-quotes. As sscanf() "[" conversion specifier only matches non-empty strings, add a special case for empty strings. Signed-off-by: Eduardo Habkost Reviewed-by: Eric Blake --- Changes v1 -> v2: * Move value[0]='\0' assignment outside if condition. Nobody seemed to like the comma operator usage in v1 (including myself), and then I noticed that it was also making checkpatch.pl sad. --- util/qemu-config.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/qemu-config.c b/util/qemu-config.c index 2d32ce7..a393a3d 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -413,7 +413,9 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) opts = qemu_opts_create(list, NULL, 0, &error_abort); continue; } - if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) { + value[0] = '\0'; + if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2 || + sscanf(line, " %63s = \"\"", arg) == 1) { /* arg = value */ if (opts == NULL) { error_report("no group defined");