Some printf implementations perform a null check on pointers passed to
%s. While that's not in the standard, this patch adds it as an option
for compatibility. It also puts a similar check in %n behind the same
flag.
Details
- Reviewers
lntue sivachandra - Commits
- rGf6ba352988b2: [libc] Add nullptr check option to printf %s
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/test/src/stdio/sprintf_test.cpp | ||
---|---|---|
101 | If the flag isn't set, the expectation is for it to segfault so it would have to be a death test. I'm not sure that's a useful test though. |
libc/src/stdio/printf_core/string_converter.h | ||
---|---|---|
29 | IIRC the traditional string is "(null)", not "null". |
IIRC the traditional string is "(null)", not "null".
That's what glibc does.
Also note for %p it uses "(nil)" instead, so go figure.
Also glibc only writes "(null)" at all if the precision allows the full string, never truncates it to "(nu" for %.3s. If it doesn't fit, it just writes nothing instead (as for an argument of "").