* [Qemu-devel] [PATCH v2] qemu-config: Accept empty option values
@ 2015-04-15 11:59 Eduardo Habkost
2015-04-15 13:06 ` Eric Blake
0 siblings, 1 reply; 2+ messages in thread
From: Eduardo Habkost @ 2015-04-15 11:59 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Gerd Hoffmann
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 <ehabkost@redhat.com>
---
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");
--
2.1.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qemu-config: Accept empty option values
2015-04-15 11:59 [Qemu-devel] [PATCH v2] qemu-config: Accept empty option values Eduardo Habkost
@ 2015-04-15 13:06 ` Eric Blake
0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2015-04-15 13:06 UTC (permalink / raw)
To: Eduardo Habkost, qemu-devel; +Cc: Paolo Bonzini, Gerd Hoffmann
[-- Attachment #1: Type: text/plain, Size: 1605 bytes --]
On 04/15/2015 05:59 AM, Eduardo Habkost wrote:
> 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 <ehabkost@redhat.com>
> ---
> 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(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
>
> 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");
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-04-15 13:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-15 11:59 [Qemu-devel] [PATCH v2] qemu-config: Accept empty option values Eduardo Habkost
2015-04-15 13:06 ` Eric Blake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).