Skip to content

Commit

Permalink
[libc][obvious] fix tests using wrong size for string
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michaelrj-google committed Nov 7, 2022
1 parent 86674f6 commit 430ca14
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libc/test/src/stdio/scanf_core/string_reader_test.cpp
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 430ca14

Please sign in to comment.