]> git.proxmox.com Git - mirror_qemu.git/commit - util/qemu-option.c
option: Assert value string isn't null
authorMarkus Armbruster <armbru@redhat.com>
Tue, 21 Feb 2017 20:13:46 +0000 (21:13 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Thu, 23 Feb 2017 19:35:35 +0000 (20:35 +0100)
commit8ee8409eff5643c677d6e5dce6620355a89c80f8
treefa3962a96b3ea7d7dab7270012da14828f9172bc
parent694baf57ae103954e2337d1fa22d1dcdfa8e2f5a
option: Assert value string isn't null

Plenty of code relies on QemuOpt member @str not being null, including
qemu_opts_print(), qemu_opts_to_qdict(), and callbacks passed to
qemu_opt_foreach().

Begs the question whether it can be null.  Only opt_set() creates
QemuOpt.  It sets member @str to its argument @value.  Passing null
for @value would plant a time bomb.  Callers:

* opts_do_parse() can't pass null.

* qemu_opt_set() passes its argument @value.  Callers:

  - qemu_opts_from_qdict_1() can't pass null

  - qemu_opts_set() passes its argument @value, but none of its
    callers pass null.

  - Many more outside qemu-option.c, but they shouldn't pass null,
    either.

Assert member @str isn't null, so that misuse is caught right away.

Simplify parse_option_bool(), parse_option_number() and
parse_option_size() accordingly.  Best viewed with whitespace changes
ignored.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1487708048-2131-3-git-send-email-armbru@redhat.com>
util/qemu-option.c