From patchwork Wed Oct 14 16:14:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bertrand Marquis X-Patchwork-Id: 11838057 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57E4814B4 for ; Wed, 14 Oct 2020 16:16:06 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 28EC5214D8 for ; Wed, 14 Oct 2020 16:16:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28EC5214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.6854.18001 (Exim 4.92) (envelope-from ) id 1kSjQP-0004CH-PE; Wed, 14 Oct 2020 16:14:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 6854.18001; Wed, 14 Oct 2020 16:14:49 +0000 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" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kSjQP-0004CA-LO; Wed, 14 Oct 2020 16:14:49 +0000 Received: by outflank-mailman (input) for mailman id 6854; Wed, 14 Oct 2020 16:14:48 +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 1kSjQO-0004C5-MX for xen-devel@lists.xenproject.org; Wed, 14 Oct 2020 16:14:48 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id f5ef3c6f-8320-4c70-94c2-87b521c2e66e; Wed, 14 Oct 2020 16:14:47 +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 83DB8D6E; Wed, 14 Oct 2020 09:14:47 -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 EC7313F71F; Wed, 14 Oct 2020 09:14:46 -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 1kSjQO-0004C5-MX for xen-devel@lists.xenproject.org; Wed, 14 Oct 2020 16:14:48 +0000 X-Inumbo-ID: f5ef3c6f-8320-4c70-94c2-87b521c2e66e Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id f5ef3c6f-8320-4c70-94c2-87b521c2e66e; Wed, 14 Oct 2020 16:14:47 +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 83DB8D6E; Wed, 14 Oct 2020 09:14:47 -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 EC7313F71F; Wed, 14 Oct 2020 09:14:46 -0700 (PDT) From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu Subject: [PATCH v2] tools/xenmpd: Fix gcc10 snprintf warning Date: Wed, 14 Oct 2020 17:14:29 +0100 Message-Id: <005bd16161fe803e9c2805bddc440db31c46169b.1602692002.git.bertrand.marquis@arm.com> X-Mailer: git-send-email 2.17.1 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=format-truncation=] This is also solving the following Debian bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=970802 Signed-off-by: Bertrand Marquis --- 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 = 0; struct dirent *dir_entries; char file_name[284]; + int ret; do { @@ -111,11 +112,15 @@ FILE *get_next_battery_file(DIR *battery_dir, if ( strlen(dir_entries->d_name) < 4 ) continue; if ( battery_info_type == BIF ) - snprintf(file_name, sizeof(file_name), BATTERY_INFO_FILE_PATH, + ret = snprintf(file_name, sizeof(file_name), BATTERY_INFO_FILE_PATH, dir_entries->d_name); else - snprintf(file_name, sizeof(file_name), BATTERY_STATE_FILE_PATH, + ret = snprintf(file_name, sizeof(file_name), BATTERY_STATE_FILE_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] = '\0'; file = fopen(file_name, "r"); } while ( !file );