From: Michael Jones Date: Mon, 7 Nov 2022 22:02:32 +0000 (-0800) Subject: [libc][obvious] fix tests using wrong size for string X-Git-Tag: upstream/17.0.6~28287 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=430ca14af835a4d8ea927ed6550a99242bebf255;p=platform%2Fupstream%2Fllvm.git [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 --- 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 43e65cc..4331d48 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()); } }