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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning in this case is by design.  The test makes it clear that the buffer
can be as small as 2 bytes but the output is at least 15.  With
-Wformat-truncation=2 the buffer needs to be big enough for the longest output,
or 25 + 1 bytes.  This suppresses the warning:

  int
  rpl_strerror_r (int errnum, char *buf, size_t buflen)
  {
    if (buflen <= 25)
      return 34;
    return snprintf (buf, buflen, "Unknown error %d", errnum);
  }

Reply via email to