From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StLi2-0001W9-OT for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StLi1-0007aO-LK for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:42:14 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:55933) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StLi1-0007aC-Ec for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:42:13 -0400 Received: by pbbro12 with SMTP id ro12so10992599pbb.4 for ; Mon, 23 Jul 2012 09:42:12 -0700 (PDT) From: riegamaths@gmail.com Date: Tue, 24 Jul 2012 00:42:20 +0800 Message-Id: <1343061740-14870-1-git-send-email-riegamaths@gmail.com> Subject: [Qemu-devel] [PATCH] vl.c: Exit QEMU early if no machine is found List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel Cc: Anthony Liguori , Stefan Hajnoczi , Dunrong Huang , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Dunrong Huang We check whether the variable machine is NULL or not before accessing it. If machine is NULL, exit QEMU with an error, this can avoids a segfault error. Signed-off-by: Dunrong Huang --- vl.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vl.c b/vl.c index 8904db1..0d145dc 100644 --- a/vl.c +++ b/vl.c @@ -3205,6 +3205,11 @@ int main(int argc, char **argv, char **envp) } loc_set_none(); + if (machine == NULL) { + fprintf(stderr, "No machine found.\n"); + exit(1); + } + if (machine->hw_version) { qemu_set_version(machine->hw_version); } @@ -3247,11 +3252,6 @@ int main(int argc, char **argv, char **envp) data_dir = CONFIG_QEMU_DATADIR; } - if (machine == NULL) { - fprintf(stderr, "No machine found.\n"); - exit(1); - } - /* * Default to max_cpus = smp_cpus, in case the user doesn't * specify a max_cpus value. -- 1.7.8.6