[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c/85139] New: Spurious format truncation warning
From:       "raj.khem at gmail dot com" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2018-03-31 4:55:36
Message-ID: bug-85139-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85139

            Bug ID: 85139
           Summary: Spurious format truncation warning
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: raj.khem at gmail dot com
  Target Milestone: ---

This test case

==================================
#include <stdio.h>
#include <stdlib.h>

extern const char *modalias_usb(const char *p, const char *v);

char s[16];

const char *modalias_usb(const char *p, const char *v) {
        int vn, pn;

        vn = strtol(v, NULL, 16);
        if (vn <= 0)
                return NULL;
        pn = strtol(p, NULL, 16);
        if (pn <= 0)
                return NULL;
        snprintf(s, sizeof(s), "usb:v%04Xp%04X*", vn, pn);
        return s;
}
========================================



Results in a format truncation warning



oe-workdir/recipe-sysroot-native/usr/bin/aarch64-bec-linux/aarch64-bec-linux-gcc
--sysroot=/mnt/a/zonit/build/tmp/work/aarch64-bec-linux/systemd/1_237-r0/recipe-sysroot
 -Wformat -O  a.c  -c -Werror
a.c: In function 'modalias_usb':
a.c:17:43: error: '%04X' directive output may be truncated writing between 4
and 8 bytes into a region of size between 2 and 6 [-Werror=format-truncation=]
         snprintf(s, sizeof(s), "usb:v%04Xp%04X*", vn, pn);
                                           ^~~~
a.c:17:32: note: directive argument in the range [1, 2147483647]
         snprintf(s, sizeof(s), "usb:v%04Xp%04X*", vn, pn);
                                ^~~~~~~~~~~~~~~~~
a.c:17:9: note: 'snprintf' output between 16 and 24 bytes into a destination of
size 16
         snprintf(s, sizeof(s), "usb:v%04Xp%04X*", vn, pn);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors


This works fine with gcc7=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic