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

            Bug ID: 88814
           Summary: transform snprintf into memccpy
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

In addition to bug 88813, prompted by the discussion of the background on
pr88793 (https://bugzilla.redhat.com/show_bug.cgi?id=1480664), another
optimization opportunity is to replace snprintf(d, n, "%s", s) calls with
non-zero n with:

  memccpy(d, s, 0, n - 1);
  d[n - 1] = 0;

Memccpy is not a standard C function but it is in POSIX so GCC configury would
have to detect support for it in order to enable it.  GCC also doesn't
recognize memccpy as a built-in so adding such support could yield additional
improvements.

Reply via email to