[all-commits] [llvm/llvm-project] b0cc7b: [libcxx] Don't use an undefined '+' in unsigned/oc...

Martin Storsjö via All-commits all-commits at lists.llvm.org
Fri Jun 4 02:09:35 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b0cc7b53a53f180c0b70b8b2f02999be78a32395
      https://github.com/llvm/llvm-project/commit/b0cc7b53a53f180c0b70b8b2f02999be78a32395
  Author: Martin Storsjö <martin at martin.st>
  Date:   2021-06-04 (Fri, 04 Jun 2021)

  Changed paths:
    M libcxx/src/locale.cpp

  Log Message:
  -----------
  [libcxx] Don't use an undefined '+' in unsigned/octal/hexal print formats

If building code like this:

    unsigned long val = 1000;
    snprintf(buf, sizeof(buf), "%+lu", val);

with clang, clang warns

    warning: flag '+' results in undefined behavior with 'u' conversion specifier [-Wformat]

Therefore, don't construct such undefined format strings. (There's
no compiler warnings here, as the compiler can't inspect dynamically
assembled format strings.)

This fixes number formatting in mingw-w64 if built with
`__USE_MINGW_ANSI_STDIO` defined (there, the '+' flag causes a
leading plus to be printed when formatting unsigned numbers too,
while the '+' flag doesn't cause any extra leading plus in other
stdio implementations).

Differential Revision: https://reviews.llvm.org/D103444




More information about the All-commits mailing list