public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/29379] New: snprintf with n greater than INT_MAX succeeds and doesn't set errno
@ 2022-07-18 21:19 msebor at gmail dot com
  2022-07-19 17:27 ` [Bug stdio/29379] " jsm28 at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gmail dot com @ 2022-07-18 21:19 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29379

            Bug ID: 29379
           Summary: snprintf with n greater than INT_MAX succeeds and
                    doesn't set errno
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: msebor at gmail dot com
  Target Milestone: ---

As an extension to C, POSIX specifies that

    The snprintf() function shall fail if:

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

Compiling the following test case with GCC produces a couple of warnings that
are meant to point this out, but running it on Linux doesn't result in the
expected output: the call doesn't return a negative value and errno is not set
to EOVERFLOW.

$ cat a.c && gcc -O -Wall a.c && ./a.out
#include <errno.h>
#include <limits.h>
#include <stdio.h>

char s[] = "123";
const size_t m1 = -1;
const size_t imaxp1 = INT_MAX + (size_t)1;

int main (void)
{
  char a[sizeof s];

  errno = 0;
  int n = snprintf (a, m1, s);
  printf ("%i (%m)\n", n);

  errno = 0;
  n = snprintf (a, imaxp1, s);
  printf ("%i (%m)\n", n);
}
a.c: In function ‘main’:
a.c:14:11: warning: specified bound 18446744073709551615 exceeds maximum object
size 9223372036854775807 [-Wformat-truncation=]
   14 |   int n = snprintf (a, m1, s);
      |           ^~~~~~~~~~~~~~~~~~~
a.c:18:7: warning: specified bound 2147483648 exceeds ‘INT_MAX’
[-Wformat-truncation=]
   18 |   n = snprintf (a, imaxp1, s);
      |       ^~~~~~~~~~~~~~~~~~~~~~~
3 (Success)
3 (Success)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug stdio/29379] snprintf with n greater than INT_MAX succeeds and doesn't set errno
  2022-07-18 21:19 [Bug stdio/29379] New: snprintf with n greater than INT_MAX succeeds and doesn't set errno msebor at gmail dot com
@ 2022-07-19 17:27 ` jsm28 at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2022-07-19 17:27 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29379

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Joseph Myers <jsm28 at gcc dot gnu.org> ---
This is bug 14771 (see the discussion there of how POSIX has failed to either
address the conflict with ISO C semantics or to raise it as a liaison issue
with WG14).

*** This bug has been marked as a duplicate of bug 14771 ***

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-19 17:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 21:19 [Bug stdio/29379] New: snprintf with n greater than INT_MAX succeeds and doesn't set errno msebor at gmail dot com
2022-07-19 17:27 ` [Bug stdio/29379] " jsm28 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).