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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC 7 does implement some additional sprintf and snprintf optimizations but it
doesn't go quite as far as you'd like it to.  The trouble is that there is no
suitable alternative function to call when the arguments aren't constant.  I
suppose in the non-constant case and for small enough positive n, snprintf(d,
n, "%s", s) could be transformed into something like

  tmp = strlen (s);
  if (n <= tmp)
    tmp = n - 1;
  memcpy (d, s, tmp);
  d[tmp] = '\0';

trading off space (more code) for speed.  But whether or not this would be a
win would depend on the snprintf implementation.  It seems to me that a better
place to implement this optimization is in snprintf itself.

Reply via email to