[libc-commits] [libc] 89b21be - [libc] Stop printing \0 in stdio/fputc_test.cpp (#220544)
via libc-commits
libc-commits at lists.llvm.org
Wed Sep 2 08:58:42 PDT 2026
Author: Simon Tatham
Date: 2026-09-02T16:58:37+01:00
New Revision: 89b21bed656009821f8c79128e7032fdddc6689b
URL: https://github.com/llvm/llvm-project/commit/89b21bed656009821f8c79128e7032fdddc6689b
DIFF: https://github.com/llvm/llvm-project/commit/89b21bed656009821f8c79128e7032fdddc6689b.diff
LOG: [libc] Stop printing \0 in stdio/fputc_test.cpp (#220544)
This test defines two strings in the form of constant char[] arrays, and
then loops over the characters of each one using a range-for. This
iteration includes the implicit terminating \0, which is printed to the
output channels along with everything else. This is mildly inconvenient
because the presence of a \0 in a log file causes standard tools like
`grep` and `less` to default to treating it as binary.
Now each loop breaks before printing the NUL, so the characters sent to
the output streams are exactly the same as in fputs_test.cpp.
Also, while I was here, I moved the check of fputc's return value into
the loop, so that it's checked on every iteration instead of just the
final one, matching the other loop checking putchar. (Surely this was
intended all along; there was no comment explaining the difference.)
Added:
Modified:
libc/test/src/stdio/fputc_test.cpp
Removed:
################################################################################
diff --git a/libc/test/src/stdio/fputc_test.cpp b/libc/test/src/stdio/fputc_test.cpp
index 614bab3b2ed4a..a309dbaad4e65 100644
--- a/libc/test/src/stdio/fputc_test.cpp
+++ b/libc/test/src/stdio/fputc_test.cpp
@@ -18,14 +18,18 @@ TEST(LlvmLibcPutcTest, PrintOut) {
constexpr char simple[] = "A simple string written to stdout\n";
for (const char &c : simple) {
+ if (!c)
+ break;
result = LIBC_NAMESPACE::putchar(c);
EXPECT_GE(result, 0);
}
constexpr char more[] = "A simple string written to stderr\n";
for (const char &c : more) {
+ if (!c)
+ break;
result = LIBC_NAMESPACE::fputc(
c, reinterpret_cast<FILE *>(LIBC_NAMESPACE::stderr));
+ EXPECT_GE(result, 0);
}
- EXPECT_GE(result, 0);
}
More information about the libc-commits
mailing list