From nobody Mon Feb 9 15:45:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487320190236752.6385354066807; Fri, 17 Feb 2017 00:29:50 -0800 (PST) Received: from localhost ([::1]:52090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cedvI-0003Ko-Q4 for importer@patchew.org; Fri, 17 Feb 2017 03:29:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cedtg-0002Y4-KS for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cedtb-0000EZ-Mo for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:08 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:35866) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cedtb-0000E3-HP for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:03 -0500 Received: by mail-pg0-x244.google.com with SMTP id a123so1590984pgc.3 for ; Fri, 17 Feb 2017 00:28:03 -0800 (PST) Received: from localhost.localdomain (v133-130-103-189.a02c.g.tyo1.static.cnode.io. [133.130.103.189]) by smtp.gmail.com with ESMTPSA id r74sm17819361pfb.67.2017.02.17.00.27.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 00:28:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dciRhJPUkemRiByEje8cmUk8CT7F7HyK0vVDD0Nao4U=; b=gNOAjf0VkWitZT+rz+9Mv0JpcB/7qci8bdsTFNtwo2HFFhjjuO+w92S78/8yJ6kNxJ r0GXVfDFna/kNH6zeQZDLqg98dwFXSFM1MciTFPz6Z4/sWzoMK8o0tkan9FtsJT2piiZ H4pnqibcz74GEySDEVv170Pr64Puuwld1jnPP0K0sFJScZXlwhfpFb3rtDriTtAzKsfZ ODJ4HsSfgBQYtVlnBRSIAixhei7YxEyw11yITzLLufUKfCKGvP3P5YfCyOa979KnfBLB apfM6/xzPoL2PsQjA5hQaCimzSQJtloG+F7+RSSH0Wu6TM/06Co5XE4/VLpqWMs3sWsC envQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dciRhJPUkemRiByEje8cmUk8CT7F7HyK0vVDD0Nao4U=; b=leBidYTdUV7mXJpfjCU5HZVngwMkJ9CmgYp2SXzt2IQf7Jg2yTh0YQMxtRto/KJ4so BI3hixsbH4Z2WSFypKaURZ8WJXaSLY6J48Wxu3EZ4WGORB6QP/QpJblj2tPFTBvQ8nK9 zwAJi5r0qwYVRlnwq8Lc16nWAKkxNFdavaAaWZBS12t653iHIRGdaEPjlYSM5PUhiwze 6EMUP1/s4EWVwAoWABePYj84czi0KtWq5dmpQ3cbFjCTaMBSINPHfEORRH3bonVCKWoE zuDY/SP9DlOteLYqtPiCzwmMbTn8ixH3Llvh7dqPAFAiw3RVZE2IR76pBYCfWoykxS5j Rm3A== X-Gm-Message-State: AMke39nu5dyg9Y8HesWaQ0E8UElwxRLpwpiHW3/XaBEK8U9Q+6lKoG3WtHQ8FsQO56qekA== X-Received: by 10.98.10.69 with SMTP id s66mr7916788pfi.146.1487320082557; Fri, 17 Feb 2017 00:28:02 -0800 (PST) From: Ziyue Yang To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 16:27:03 +0800 Message-Id: <20170217082704.23270-2-skiver.cloud.yzy@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170217082704.23270-1-skiver.cloud.yzy@gmail.com> References: <20170217082704.23270-1-skiver.cloud.yzy@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH 1/2] monitor.c: make mon_get_cpu return NULL when there is no CPU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ziyue Yang , Ziyue Yang , "Dr . David Alan Gilbert" , Pavel Butsykin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ziyue Yang Currently mon_get_cpu always dereferences first_cpu without checking whether it's a valid pointer. This commit adds check before dereferencing, and reports "No CPU" info if there isn't any CPU then returns NULL. Signed-off-by: Ziyue Yang Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- monitor.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/monitor.c b/monitor.c index 3cd72a9bab..6b25cf7a2b 100644 --- a/monitor.c +++ b/monitor.c @@ -1026,6 +1026,10 @@ int monitor_set_cpu(int cpu_index) CPUState *mon_get_cpu(void) { if (!cur_mon->mon_cpu) { + if (!first_cpu) { + monitor_printf(cur_mon, "No CPU available on this machine\n"); + return NULL; + } monitor_set_cpu(first_cpu->cpu_index); } cpu_synchronize_state(cur_mon->mon_cpu); @@ -2495,11 +2499,11 @@ static int default_fmt_size =3D 4; static int is_valid_option(const char *c, const char *typestr) { char option[3]; - =20 + option[0] =3D '-'; option[1] =3D *c; option[2] =3D '\0'; - =20 + typestr =3D strstr(typestr, option); return (typestr !=3D NULL); } @@ -2864,7 +2868,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, p++; if(c !=3D *p) { if(!is_valid_option(p, typestr)) { - =20 + monitor_printf(mon, "%s: unsupported option -%= c\n", cmd->name, *p); goto fail; --=20 2.11.0