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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Note that with snprintf GCC issues

  warning: ā€˜%sā€™ directive output may be truncated writing between 1 and 11
bytes into a region of size 5

This is also by design though I'm on the fence about warning at the same level
or under the same option as for sprintf.

FWIW, I wouldn't expect the parsing of the precision within the format string
to have a noticeable performance impact on the overall cost of the call to the
function.  If you prefer to avoid it, you can specify via an argument to the
'*':

  sprintf(foo, "zz%.*s", 4, s.buf);

I'm changing the resolution of this bug to invalid since we haven't actually
fixed anything, but if none of the solutions above is sufficient please feel
free to reopen the bug and let us know what would be (keeping in mind that the
ideal solution of tracking the actual string length or its range or determining
it from the strlen call may not be feasible in the near term).

Reply via email to