From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Chunyan Liu <cyliu@suse.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 3/6] QemuOpts: check NULL opts in qemu_opt_get functions
Date: Mon, 23 Jun 2014 17:31:16 +0800 [thread overview]
Message-ID: <1403515879-14359-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1403515879-14359-1-git-send-email-stefanha@redhat.com>
From: Chunyan Liu <cyliu@suse.com>
Some places will call bdrv_create_file(filename, NULL, &local_err), where
opts is NULL. Check NULL in qemu_opt_get and qemu_opt_get_*_del functions,
to avoid extra effort of checking opts before calling them every time.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
util/qemu-option.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 836055a..43de3ad 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -310,8 +310,13 @@ static void qemu_opt_del_all(QemuOpts *opts, const char *name)
const char *qemu_opt_get(QemuOpts *opts, const char *name)
{
- QemuOpt *opt = qemu_opt_find(opts, name);
+ QemuOpt *opt;
+ if (opts == NULL) {
+ return NULL;
+ }
+
+ opt = qemu_opt_find(opts, name);
if (!opt) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
@@ -364,9 +369,14 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
static bool qemu_opt_get_bool_helper(QemuOpts *opts, const char *name,
bool defval, bool del)
{
- QemuOpt *opt = qemu_opt_find(opts, name);
+ QemuOpt *opt;
bool ret = defval;
+ if (opts == NULL) {
+ return ret;
+ }
+
+ opt = qemu_opt_find(opts, name);
if (opt == NULL) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
@@ -395,9 +405,14 @@ bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
static uint64_t qemu_opt_get_number_helper(QemuOpts *opts, const char *name,
uint64_t defval, bool del)
{
- QemuOpt *opt = qemu_opt_find(opts, name);
+ QemuOpt *opt;
uint64_t ret = defval;
+ if (opts == NULL) {
+ return ret;
+ }
+
+ opt = qemu_opt_find(opts, name);
if (opt == NULL) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
@@ -427,9 +442,14 @@ uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
static uint64_t qemu_opt_get_size_helper(QemuOpts *opts, const char *name,
uint64_t defval, bool del)
{
- QemuOpt *opt = qemu_opt_find(opts, name);
+ QemuOpt *opt;
uint64_t ret = defval;
+ if (opts == NULL) {
+ return ret;
+ }
+
+ opt = qemu_opt_find(opts, name);
if (opt == NULL) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
--
1.9.3
next prev parent reply other threads:[~2014-06-23 9:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-23 9:31 [Qemu-devel] [PULL 0/6] Block patches Stefan Hajnoczi
2014-06-23 9:31 ` [Qemu-devel] [PULL 1/6] block: m25p80: sync_page(): Deindent function body Stefan Hajnoczi
2014-06-23 9:31 ` [Qemu-devel] [PULL 2/6] block: m25p80: Support read only bdrvs Stefan Hajnoczi
2014-06-23 9:31 ` Stefan Hajnoczi [this message]
2014-06-23 9:31 ` [Qemu-devel] [PULL 4/6] sheepdog: fix NULL dereference in sd_create Stefan Hajnoczi
2014-06-23 9:31 ` [Qemu-devel] [PULL 5/6] vl: allow other threads to do qemu_system_vmstop_request Stefan Hajnoczi
2014-06-23 9:31 ` [Qemu-devel] [PULL 6/6] block: asynchronously stop the VM on I/O errors Stefan Hajnoczi
2014-06-23 12:18 ` [Qemu-devel] [PULL 0/6] Block patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1403515879-14359-4-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=cyliu@suse.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).