[libc-commits] [libc] 223261c - Fix broken libc test
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Wed Jul 7 09:48:07 PDT 2021
Author: Guillaume Chatelet
Date: 2021-07-07T16:47:49Z
New Revision: 223261cbaa6b4c74cf9eebca3452ec0d15ea018e
URL: https://github.com/llvm/llvm-project/commit/223261cbaa6b4c74cf9eebca3452ec0d15ea018e
DIFF: https://github.com/llvm/llvm-project/commit/223261cbaa6b4c74cf9eebca3452ec0d15ea018e.diff
LOG: Fix broken libc test
Added:
Modified:
libc/test/src/string/memcmp_test.cpp
Removed:
################################################################################
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 <cstring>
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';
More information about the libc-commits
mailing list