Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.bugs.dist > #1026170

Bug#970802: gcc-10: armhf: false positive when using -O2 and -Werror=format-truncation

From Julien Grall <julien@xen.org>
Newsgroups linux.debian.bugs.dist
Subject Bug#970802: gcc-10: armhf: false positive when using -O2 and -Werror=format-truncation
Date 2020-09-23 17:50 +0200
Message-ID <ASfbP-86q-5@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


X-Debbugs-CC: iwj@xenproject.org
X-Debbugs-CC: hans@knorrie.org
Package: gcc-10
Version: 10.2.0-9
Severity: important

Dear Maintainer,

There was an FTBFS for Xen when building using GCC 10 on armhf (see
bug #9689645 [1]).

After investigation, it looks a problem when with the optimizer in GCC 
for armhf.

The issue was narrowed down to the following code:

42sh> cat test.c
#include <stdio.h>
#include <string.h>
#include <dirent.h>

char *tmp(struct dirent *dir_entry)
{
     static char file_name[284];

     if ( strlen(dir_entry->d_name) < 4 )
         return NULL;

     snprintf(file_name, sizeof(file_name), "%s",
              dir_entry->d_name);

     return file_name;
}

42sh> gcc -Wall -Werror -O2 -c test.c
test.c: In function 'tmp':
test.c:12:45: error: '%s' directive output may be truncated writing 
between 4 and 2147483645 bytes into a region of size 284 
[-Werror=format-truncation=]
    12 |     snprintf(file_name, sizeof(file_name), "%s",
       |                                             ^~
test.c:12:5: note: 'snprintf' output between 5 and 2147483646 bytes into 
a destination of size 284
    12 |     snprintf(file_name, sizeof(file_name), "%s",
       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    13 |              dir_entry->d_name);
       |              ~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Removing the length check will allow GCC to compile the object
sucessfully.

Would it be possible to investigate the root cause in GCC?

Cheers,

-- System Information:
Debian Release: bullseye/sid
   APT prefers unstable
   APT policy: (500, 'unstable')
Architecture: armhf (armv7l)

-- 
Julien Grall

Back to linux.debian.bugs.dist | Previous | Next | Find similar | Unroll thread


Thread

Bug#970802: gcc-10: armhf: false positive when using -O2 and -Werror=format-truncation Julien Grall <julien@xen.org> - 2020-09-23 17:50 +0200

csiph-web