vl.c: Fix Coverity complaining for vmstate_dump_file
authorGonglei <arei.gonglei@huawei.com>
Wed, 29 Oct 2014 12:49:43 +0000 (20:49 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 31 Oct 2014 10:29:01 +0000 (11:29 +0100)
commit abfd9ce3(migration: dump vmstate info as a json
file for static analysis) introduce a new command,
'-dump-vmstate', that takes a filename
as an argument.  When executed, QEMU will dump the vmstate information
for the machine type it's invoked with to the file, and quit.

However, only one instance of the -dump-vmstate option is supported.
If more were given, the vmstate_dump_file variable would be overwritten.

This fix also helps silence a Coverity error.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vl.c

diff --git a/vl.c b/vl.c
index f5721d1f25748ad8e8152cc302cccfa3d2ad58ef..f070c90826aabcfe3af14c4065c75a94ca278fb1 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -3750,6 +3750,11 @@ int main(int argc, char **argv, char **envp)
                 configure_msg(opts);
                 break;
             case QEMU_OPTION_dump_vmstate:
+                if (vmstate_dump_file) {
+                    fprintf(stderr, "qemu: only one '-dump-vmstate' "
+                            "option may be given\n");
+                    exit(1);
+                }
                 vmstate_dump_file = fopen(optarg, "w");
                 if (vmstate_dump_file == NULL) {
                     fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));