[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tools/xenmpd: Fix gcc10 snprintf warning


  • To: Julien Grall <julien@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 14 Oct 2020 11:58:13 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iXDvGh9JfxV1PiZF6bms5+G/a1l1NrVGtErsneUHUUs=; b=IQl7/H2BBklCEUQb31ltTNoW7O8bQPM6/AIOSDkFI+dze8nXtmWtbnVEKgSrUK8JAZAsVg66lkvX0P4Ql867hZyaTcoEPWqWdhsjiyFVtscNe89tIluWPHEn59pU2T3P8TNU0NXrHgR/JrneoHVeS1ljoqZcfwvrZ/6a2nvk6A24wD5ZYm9zVJicP5VahdUVu8KBim0ixHh+pets898yAEvfvpfiBXTOeNvrvu9mki66Mhe2xWh4pWSi0ulEK/5poLbfVf9Z0AYZHtfgxCiV1V/d9eFEQcXk2f63q/kH0yWgD4rA3hfg4Nse3mHOhZ+OlJNHankk3KLstvw0gV17/A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lELGnCdbQfB583zZp3Abo5qj0z7qT7k9wuhKuaxc5Pws5GUpmDoI0F7+GjesBfxSdiB0pANigyQ5/GKz5N+dSdpejnA0x8QKVV4Vyn+958Mq2TBaSGeeKyth2eNyChhKXRdOe4E3jp4m9beZztdkhJ26UWE47PJg6NsdrIgXt0S8plW5ALiHoBKFjbMA7Q81/Vf29y74vDS0Gc3hsiS6EsaeLmQDMszdKUwViikLBWtS5cOywT5prL/bXr6OI5IgTuI15M8GmXy56hVKIS5FDPhix7PZfC7OoRtQd8P9jOE1O54zm4m+uasrbTMziNZ/erRi9eXAJLzuEPymXvclNA==
  • Authentication-results-original: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Cc: "open list:X86" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Wed, 14 Oct 2020 11:58:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHWoheQbJERqQUoxES88omBLvhPP6mW73mAgAAO7YA=
  • Thread-topic: [PATCH] tools/xenmpd: Fix gcc10 snprintf warning

Hi Julien,

> On 14 Oct 2020, at 12:04, Julien Grall <julien@xxxxxxx> wrote:
> 
> 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 can confirm this is the only build catching it on my side.

I will modify the commit message to say that the problem was encountered on 
arm32 build with the optimizer enabled.

> 
> I would also suggest to link to the bug reported on Debian.

I will add it to the commit message.

Cheers
Bertrand

> 
> Cheers,
> 
>> Signed-off-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
>> ---
>>  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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.