llvm-project
ab60910e - [libc++][format] Discard contents since null-terminator in character arrays in formatting (#116571)

Commit
140 days ago
[libc++][format] Discard contents since null-terminator in character arrays in formatting (#116571) Currently, built-in `char`/`wchar_t` arrays are assumed to be null-terminated sequence with the terminator being the last element in formatting. This doesn't conform to [format.arg]/6.9. > otherwise, if `decay_t<TD>` is `char_type*` or `const char_type*`, > initializes value with `static_cast<const char_type*>(v)`; The standard wording specifies that character arrays are decayed to pointers. When the null terminator is not the last element or there's no null terminator (the latter case is UB), libc++ currently produces different results. Also fixes and hardens `formatter<CharT[N], CharT>::format` in `<__format/formatter_string.h>`. These specializations are rarely used. Fixes #115935. Also checks the preconditions in this case, which fixes #116570.
Parents
Loading