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

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



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


Reply to: