[libc-commits] [PATCH] D137586: [libc][obvious] fix tests using wrong size for string
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Mon Nov 7 14:04:27 PST 2022
michaelrj created this revision.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
michaelrj requested review of this revision.
In the code
const char *str = "abc"
if you do sizeof(str) you get the size of the pointer, not the string.
This patch fixes that mistake.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137586
Files:
libc/test/src/stdio/scanf_core/string_reader_test.cpp
Index: libc/test/src/stdio/scanf_core/string_reader_test.cpp
===================================================================
--- libc/test/src/stdio/scanf_core/string_reader_test.cpp
+++ libc/test/src/stdio/scanf_core/string_reader_test.cpp
@@ -23,7 +23,7 @@
__llvm_libc::scanf_core::StringReader str_reader(str);
__llvm_libc::scanf_core::Reader reader(&str_reader);
- for (size_t i = 0; i < sizeof(str); ++i) {
+ for (size_t i = 0; i < sizeof("abc"); ++i) {
ASSERT_EQ(str[i], reader.getc());
}
}
@@ -60,7 +60,7 @@
}
// Check the whole string.
- for (size_t i = 0; i < sizeof(str); ++i) {
+ for (size_t i = 0; i < sizeof("abcDEF123"); ++i) {
ASSERT_EQ(str[i], reader.getc());
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137586.473785.patch
Type: text/x-patch
Size: 722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221107/60cc1dd5/attachment.bin>
More information about the libc-commits
mailing list