qemu-config: Accept empty option values
PATCH v2 1/1 qemu-config: Accept empty option values
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.
---
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(-)
util/qemu-config.c +3 -1
@@ -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" );
Signature · 1 line
2.1.0
Quoted 8 lines · Eduardo Habkost
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 <[email protected]>
Quoted 8 lines
---
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(-)
Quoted 17 lines
util/qemu-config.c +3
-1@@ -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" );
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org