[Bug rtl-optimization/87096] New: "Optimised" snprintf is not POSIX conformant

awilfox at adelielinux dot org gcc-bugzilla@gcc.gnu.org
Fri Aug 24 18:39:00 GMT 2018


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

            Bug ID: 87096
           Summary: "Optimised" snprintf is not POSIX conformant
           Product: gcc
           Version: 6.4.0
               URL: http://pubs.opengroup.org/onlinepubs/9699919799/functi
                    ons/snprintf.html
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: awilfox at adelielinux dot org
  Target Milestone: ---

POSIX Issue 7, 2018 edition (see URL)

The snprintf() function shall fail if:

[EOVERFLOW]
    The value of n is greater than {INT_MAX}.


This behaviour may or may not be ISO C compatible: C99 WG14 and C11
specifically state that intending the printf family of functions to return
larger than INT_MAX is undefined behaviour: J.2.  I am unclear on the status of
this behaviour with regards to C89.  It is definitely required by POSIX.

The following line of C, which is the minimum reproduction case:

snprintf(buf, (size_t)INT_MAX + 1, "");

returns 0 when compiled with GCC unless -fno-builtin is passed.


More information about the Gcc-bugs mailing list