Skip to content

Commit 223261c

Browse files
committed
Fix broken libc test
1 parent ded8866 commit 223261c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

libc/test/src/string/memcmp_test.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "src/string/memcmp.h"
1010
#include "utils/UnitTest/Test.h"
11-
#include <cstring>
1211

1312
TEST(LlvmLibcMemcmpTest, CmpZeroByte) {
1413
const char *lhs = "ab";
@@ -39,14 +38,19 @@ TEST(LlvmLibcMemcmpTest, Sweep) {
3938
char lhs[kMaxSize];
4039
char rhs[kMaxSize];
4140

42-
memset(lhs, 'a', sizeof(lhs));
43-
memset(rhs, 'a', sizeof(rhs));
44-
for (int i = 0; i < kMaxSize; ++i)
41+
const auto reset = [](char *const ptr) {
42+
for (size_t i = 0; i < kMaxSize; ++i)
43+
ptr[i] = 'a';
44+
};
45+
46+
reset(lhs);
47+
reset(rhs);
48+
for (size_t i = 0; i < kMaxSize; ++i)
4549
EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, i), 0);
4650

47-
memset(lhs, 'a', sizeof(lhs));
48-
memset(rhs, 'a', sizeof(rhs));
49-
for (int i = 0; i < kMaxSize; ++i) {
51+
reset(lhs);
52+
reset(rhs);
53+
for (size_t i = 0; i < kMaxSize; ++i) {
5054
rhs[i] = 'b';
5155
EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, kMaxSize), -1);
5256
rhs[i] = 'a';

0 commit comments

Comments
 (0)