From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7E3A4C433EF for ; Mon, 10 Jan 2022 02:05:48 +0000 (UTC) Received: from localhost ([::1]:44094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n6k4B-0004bD-KX for qemu-devel@archiver.kernel.org; Sun, 09 Jan 2022 21:05:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6k2i-0003iI-Kk; Sun, 09 Jan 2022 21:04:16 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]:3075) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6k2a-000284-N2; Sun, 09 Jan 2022 21:04:11 -0500 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JXHD52T5czbjBQ; Mon, 10 Jan 2022 10:03:17 +0800 (CST) Received: from [10.174.187.128] (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Mon, 10 Jan 2022 10:03:54 +0800 Subject: Re: [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers To: Thomas Huth , , Alistair Francis CC: Andrew Jones , David Gibson , References: <20220107133844.145039-1-thuth@redhat.com> Message-ID: Date: Mon, 10 Jan 2022 10:03:54 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20220107133844.145039-1-thuth@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggeme708-chm.china.huawei.com (10.1.199.104) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.188; envelope-from=wangyanan55@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: "wangyanan (Y)" From: "wangyanan (Y)" via On 2022/1/7 21:38, Thomas Huth wrote: > If I configure my build with --enable-sanitizers, my GCC (v8.5.0) > complains: > > .../softmmu/device_tree.c: In function ‘qemu_fdt_add_path’: > .../softmmu/device_tree.c:560:18: error: ‘retval’ may be used uninitialized > in this function [-Werror=maybe-uninitialized] > int namelen, retval; > ^~~~~~ > > It's a false warning since the while loop is always executed at least > once (p has to be non-NULL, otherwise the derefence in the if-statement > earlier will crash). Thus let's switch to a do-while loop here instead > to make the compiler happy in all cases. > > Signed-off-by: Thomas Huth > --- > softmmu/device_tree.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) Reviewed-by: Yanan Wang > diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c > index 3965c834ca..9e96f5ecd5 100644 > --- a/softmmu/device_tree.c > +++ b/softmmu/device_tree.c > @@ -564,7 +564,7 @@ int qemu_fdt_add_path(void *fdt, const char *path) > return -1; > } > > - while (p) { > + do { > name = p + 1; > p = strchr(name, '/'); > namelen = p != NULL ? p - name : strlen(name); > @@ -584,7 +584,7 @@ int qemu_fdt_add_path(void *fdt, const char *path) > } > > parent = retval; > - } > + } while (p); > > return retval; > }