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 X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6387BC433DF for ; Wed, 14 Oct 2020 11:05:05 +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 AA508206D5 for ; Wed, 14 Oct 2020 11:05:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="QBlSnn4m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA508206D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org 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.6594.17516 (Exim 4.92) (envelope-from ) id 1kSeaS-0006um-SX; Wed, 14 Oct 2020 11:04:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 6594.17516; Wed, 14 Oct 2020 11:04:52 +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 1kSeaS-0006uf-P1; Wed, 14 Oct 2020 11:04:52 +0000 Received: by outflank-mailman (input) for mailman id 6594; Wed, 14 Oct 2020 11:04:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kSeaR-0006ua-Mo for xen-devel@lists.xenproject.org; Wed, 14 Oct 2020 11:04:51 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5120364f-f58c-4010-943f-74cda842a6f3; Wed, 14 Oct 2020 11:04:51 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kSeaP-0002Lu-Vo; Wed, 14 Oct 2020 11:04:49 +0000 Received: from [54.239.6.185] (helo=a483e7b01a66.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSeaP-0003CB-Lf; Wed, 14 Oct 2020 11:04:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kSeaR-0006ua-Mo for xen-devel@lists.xenproject.org; Wed, 14 Oct 2020 11:04:51 +0000 X-Inumbo-ID: 5120364f-f58c-4010-943f-74cda842a6f3 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5120364f-f58c-4010-943f-74cda842a6f3; Wed, 14 Oct 2020 11:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=bYs1e4B6dk8FulF7Wjnn1eQPo1MDL6NA3+DdZL+x0B0=; b=QBlSnn4mPfGuA6ijYGt4cWnSP6 Jk4uld1GPNeJR4MTRMj6fAx9FNCqwBkR4ADZE8hda7gVS5MxVLSkhjltQB5O8gTUkEgvmQBH06g75 42/jb9wIA4i1ZT2FdJNJLZ9NVppwwJ079XTxvn2h+pfYfB0vDTpRgPzq0UsGrOtAbX8s=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kSeaP-0002Lu-Vo; Wed, 14 Oct 2020 11:04:49 +0000 Received: from [54.239.6.185] (helo=a483e7b01a66.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSeaP-0003CB-Lf; Wed, 14 Oct 2020 11:04:49 +0000 Subject: Re: [PATCH] tools/xenmpd: Fix gcc10 snprintf warning To: Bertrand Marquis , xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu References: <0ade4264c537819c3dd45179fcea2723df66b045.1602672245.git.bertrand.marquis@arm.com> From: Julien Grall Message-ID: <74625fd9-f2a3-14be-714a-3cfb705434cc@xen.org> Date: Wed, 14 Oct 2020 12:04:47 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 MIME-Version: 1.0 In-Reply-To: <0ade4264c537819c3dd45179fcea2723df66b045.1602672245.git.bertrand.marquis@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Hi, On 14/10/2020 11:47, Bertrand Marquis wrote: > 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 gcc warning: > 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=] IIRC, this is only affecting GCC when building for Arm32 *and* when the optimizer is enabled. If so, it would be good to add more details in the commit message. I would also suggest to link to the bug reported on Debian. Cheers, > > 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 ); > > Cheers, -- Julien Grall