From 223261cbaa6b4c74cf9eebca3452ec0d15ea018e Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Wed, 7 Jul 2021 16:47:49 +0000 Subject: [PATCH] Fix broken libc test --- libc/test/src/string/memcmp_test.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libc/test/src/string/memcmp_test.cpp b/libc/test/src/string/memcmp_test.cpp index 81b6709205fd..9be1e56302f8 100644 --- a/libc/test/src/string/memcmp_test.cpp +++ b/libc/test/src/string/memcmp_test.cpp @@ -8,7 +8,6 @@ #include "src/string/memcmp.h" #include "utils/UnitTest/Test.h" -#include TEST(LlvmLibcMemcmpTest, CmpZeroByte) { const char *lhs = "ab"; @@ -39,14 +38,19 @@ TEST(LlvmLibcMemcmpTest, Sweep) { char lhs[kMaxSize]; char rhs[kMaxSize]; - memset(lhs, 'a', sizeof(lhs)); - memset(rhs, 'a', sizeof(rhs)); - for (int i = 0; i < kMaxSize; ++i) + const auto reset = [](char *const ptr) { + for (size_t i = 0; i < kMaxSize; ++i) + ptr[i] = 'a'; + }; + + reset(lhs); + reset(rhs); + for (size_t i = 0; i < kMaxSize; ++i) EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, i), 0); - memset(lhs, 'a', sizeof(lhs)); - memset(rhs, 'a', sizeof(rhs)); - for (int i = 0; i < kMaxSize; ++i) { + reset(lhs); + reset(rhs); + for (size_t i = 0; i < kMaxSize; ++i) { rhs[i] = 'b'; EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, kMaxSize), -1); rhs[i] = 'a';