[PATCH] D67986: [InstCombine] snprintf (d, size, "%s", s) -> memccpy (d, s, '\0', size - 1), d[size - 1] = 0

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 13:58:48 PDT 2019


efriedma added a comment.

Oh, hmm... actually, just realized something; is the new formulation actually equivalent?  Specifically, is it okay to write to "d[size - 1]" if the string is short?  Say, for example, you have something like `snprintf(buf, 10, "%s", "x")`.  That normally writes to two elements of the array: 0 and 1.  The rewritten version writes to three elements: 0, 1, and 9.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67986/new/

https://reviews.llvm.org/D67986





More information about the llvm-commits mailing list