[libc-commits] [libc] 430ca14 - [libc][obvious] fix tests using wrong size for string
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Mon Nov 7 14:04:46 PST 2022
Author: Michael Jones
Date: 2022-11-07T14:04:39-08:00
New Revision: 430ca14af835a4d8ea927ed6550a99242bebf255
URL: https://github.com/llvm/llvm-project/commit/430ca14af835a4d8ea927ed6550a99242bebf255
DIFF: https://github.com/llvm/llvm-project/commit/430ca14af835a4d8ea927ed6550a99242bebf255.diff
LOG: [libc][obvious] fix tests using wrong size for string
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.
Differential Revision: https://reviews.llvm.org/D137586
Added:
Modified:
libc/test/src/stdio/scanf_core/string_reader_test.cpp
Removed:
################################################################################
diff --git a/libc/test/src/stdio/scanf_core/string_reader_test.cpp b/libc/test/src/stdio/scanf_core/string_reader_test.cpp
index 43e65cc1bab6..4331d488be06 100644
--- a/libc/test/src/stdio/scanf_core/string_reader_test.cpp
+++ b/libc/test/src/stdio/scanf_core/string_reader_test.cpp
@@ -23,7 +23,7 @@ TEST(LlvmLibcScanfStringReaderTest, SimpleRead) {
__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 @@ TEST(LlvmLibcScanfStringReaderTest, ReadAndReverse) {
}
// 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());
}
}
More information about the libc-commits
mailing list