From nobody Wed Apr 24 02:55:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1602753404; cv=none; d=zohomail.com; s=zohoarc; b=goRgeuFdnC+1xe254f5kwXprUE0HxMJ4G6Xa5cUEtW3AbAeAxzwmdRFIYyDutdIE3noR/jRdaO7HyAZ2XAm7c+yYnCgGhWMs8eCh6WWa8osKW1a1t6fHtaQbpQGj7s7mOXYCKwiFygeM315oP87X+Mxo5hm5rj2FQ2FHvbkRboc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602753404; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=4mfC/IjiPyebY8IwcBftXDnRa3szmf7jYGc7Ot/n94Q=; b=OHGvlBGgMdbPUEL34WeI8goAxtE14GptjWhuCK4rtl+huWOswDO+Arwcm/+OmeE6oRax70mEu5wiACXe9IppatfjF7sDaStlTXM9dxeibzl6aYpdp5UDWflJm5bpbHEWFxKPjue/gbYeYTmkQ1VujmQtMW4w7L0Gva0yQGLh0Bs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602753404942994.734289236554; Thu, 15 Oct 2020 02:16:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.7163.18803 (Exim 4.92) (envelope-from ) id 1kSzN9-0006lL-1p; Thu, 15 Oct 2020 09:16:31 +0000 Received: by outflank-mailman (output) from mailman id 7163.18803; Thu, 15 Oct 2020 09:16:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kSzN8-0006lC-Ui; Thu, 15 Oct 2020 09:16:30 +0000 Received: by outflank-mailman (input) for mailman id 7163; Thu, 15 Oct 2020 09:16:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kSzN7-0006kj-Hr for xen-devel@lists.xenproject.org; Thu, 15 Oct 2020 09:16:29 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id c9d6dfcc-03f4-45c6-8752-cdef913e6fba; Thu, 15 Oct 2020 09:16:29 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DADA813D5; Thu, 15 Oct 2020 02:16:28 -0700 (PDT) Received: from e109506-lin.cambridge.arm.com (e109506-lin.cambridge.arm.com [10.1.198.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 504323F66B; Thu, 15 Oct 2020 02:16:28 -0700 (PDT) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kSzN7-0006kj-Hr for xen-devel@lists.xenproject.org; Thu, 15 Oct 2020 09:16:29 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id c9d6dfcc-03f4-45c6-8752-cdef913e6fba; Thu, 15 Oct 2020 09:16:29 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DADA813D5; Thu, 15 Oct 2020 02:16:28 -0700 (PDT) Received: from e109506-lin.cambridge.arm.com (e109506-lin.cambridge.arm.com [10.1.198.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 504323F66B; Thu, 15 Oct 2020 02:16:28 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c9d6dfcc-03f4-45c6-8752-cdef913e6fba From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu Subject: [PATCH v3] tools/xenpmd: Fix gcc10 snprintf warning Date: Thu, 15 Oct 2020 10:16:09 +0100 Message-Id: <14ac4900dcf4fb9b45ce4f5e3d60de7f7e3602ab.1602753323.git.bertrand.marquis@arm.com> X-Mailer: git-send-email 2.17.1 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a check for snprintf return code and ignore the entry if we get an error. This should in fact never happen and is more a trick to make gcc happy and prevent compilation errors. This is solving the following gcc warning when compiling for arm32 host platforms with optimization activated: xenpmd.c:92:37: error: '%s' directive output may be truncated writing between 4 and 2147483645 bytes into a region of size 271 [-Werror=3Dformat-truncation=3D] This is also solving the following Debian bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D970802 Signed-off-by: Bertrand Marquis Acked-by: Wei Liu --- tools/xenpmd/xenpmd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c index 35fd1c931a..12b82cf43e 100644 --- a/tools/xenpmd/xenpmd.c +++ b/tools/xenpmd/xenpmd.c @@ -102,6 +102,7 @@ FILE *get_next_battery_file(DIR *battery_dir, FILE *file =3D 0; struct dirent *dir_entries; char file_name[284]; + int ret; =20 do=20 { @@ -111,11 +112,15 @@ FILE *get_next_battery_file(DIR *battery_dir, if ( strlen(dir_entries->d_name) < 4 ) continue; if ( battery_info_type =3D=3D BIF )=20 - snprintf(file_name, sizeof(file_name), BATTERY_INFO_FILE_PATH, + ret =3D snprintf(file_name, sizeof(file_name), BATTERY_INFO_FI= LE_PATH, dir_entries->d_name); else=20 - snprintf(file_name, sizeof(file_name), BATTERY_STATE_FILE_PATH, + ret =3D snprintf(file_name, sizeof(file_name), BATTERY_STATE_F= ILE_PATH, dir_entries->d_name); + /* This should not happen but is needed to pass gcc checks */ + if (ret < 0) + continue; + file_name[sizeof(file_name) - 1] =3D '\0'; file =3D fopen(file_name, "r"); } while ( !file ); =20 --=20 2.17.1