From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz0bP-0002Ni-E8 for qemu-devel@nongnu.org; Mon, 23 Jun 2014 05:31:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz0bK-0004Yk-FV for qemu-devel@nongnu.org; Mon, 23 Jun 2014 05:31:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57028) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz0bK-0004Yd-6y for qemu-devel@nongnu.org; Mon, 23 Jun 2014 05:31:46 -0400 From: Stefan Hajnoczi Date: Mon, 23 Jun 2014 17:31:16 +0800 Message-Id: <1403515879-14359-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1403515879-14359-1-git-send-email-stefanha@redhat.com> References: <1403515879-14359-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 3/6] QemuOpts: check NULL opts in qemu_opt_get functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Chunyan Liu , Stefan Hajnoczi From: Chunyan Liu 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 Reviewed-by: Eric Blake Signed-off-by: Stefan Hajnoczi --- 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