diff --git a/libc/test/src/string/memory_utils/memory_check_utils.h b/libc/test/src/string/memory_utils/memory_check_utils.h --- a/libc/test/src/string/memory_utils/memory_check_utils.h +++ b/libc/test/src/string/memory_utils/memory_check_utils.h @@ -55,7 +55,7 @@ char *offset_ptr = nullptr; }; -static inline char GetRandomChar() { +inline char GetRandomChar() { static constexpr const uint64_t a = 1103515245; static constexpr const uint64_t c = 12345; static constexpr const uint64_t m = 1ULL << 31; @@ -65,19 +65,18 @@ } // Randomize the content of the buffer. -static inline void Randomize(cpp::span buffer) { +inline void Randomize(cpp::span buffer) { for (auto ¤t : buffer) current = GetRandomChar(); } // Copy one span to another. -static inline void ReferenceCopy(cpp::span dst, - const cpp::span src) { +inline void ReferenceCopy(cpp::span dst, const cpp::span src) { for (size_t i = 0; i < dst.size(); ++i) dst[i] = src[i]; } -static inline bool IsEqual(const cpp::span a, const cpp::span b) { +inline bool IsEqual(const cpp::span a, const cpp::span b) { LIBC_ASSERT(a.size() == b.size()); for (size_t i = 0; i < a.size(); ++i) if (a[i] != b[i]) @@ -87,7 +86,7 @@ // Checks that FnImpl implements the memcpy semantic. template -bool CheckMemcpy(cpp::span dst, cpp::span src, size_t size) { +inline bool CheckMemcpy(cpp::span dst, cpp::span src, size_t size) { Randomize(dst); FnImpl(dst, src, size); return IsEqual(dst, src); @@ -95,7 +94,7 @@ // Checks that FnImpl implements the memset semantic. template -bool CheckMemset(cpp::span dst, uint8_t value, size_t size) { +inline bool CheckMemset(cpp::span dst, uint8_t value, size_t size) { Randomize(dst); FnImpl(dst, value, size); for (char c : dst) @@ -106,7 +105,8 @@ // Checks that FnImpl implements the bcmp semantic. template -bool CheckBcmp(cpp::span span1, cpp::span span2, size_t size) { +inline bool CheckBcmp(cpp::span span1, cpp::span span2, + size_t size) { ReferenceCopy(span2, span1); // Compare equal if (int cmp = FnImpl(span1, span2, size); cmp != 0) @@ -125,7 +125,8 @@ // Checks that FnImpl implements the memcmp semantic. template -bool CheckMemcmp(cpp::span span1, cpp::span span2, size_t size) { +inline bool CheckMemcmp(cpp::span span1, cpp::span span2, + size_t size) { ReferenceCopy(span2, span1); // Compare equal if (int cmp = FnImpl(span1, span2, size); cmp != 0) @@ -150,7 +151,7 @@ return true; } -uint16_t Checksum(cpp::span dst) { +inline uint16_t Checksum(cpp::span dst) { // We use Fletcher16 as it is trivial to implement. uint16_t sum1 = 0; uint16_t sum2 = 0; @@ -158,11 +159,11 @@ sum1 = (sum1 + c) % 255U; sum2 = (sum2 + sum1) % 255U; } - return (sum2 << 8) | sum1; + return static_cast((sum2 << 8) | sum1); } template -bool CheckMemmove(cpp::span dst, cpp::span src) { +inline bool CheckMemmove(cpp::span dst, cpp::span src) { LIBC_ASSERT(dst.size() == src.size()); // Memmove can override the src buffer. Technically we should save it into a // temporary buffer so we can check that 'dst' is equal to what 'src' was @@ -180,7 +181,7 @@ // - zero mean they overlap exactly // - Caller is responsible for randomizing the buffer. template -bool CheckMemmove(cpp::span buffer, size_t size, int overlap) { +inline bool CheckMemmove(cpp::span buffer, size_t size, int overlap) { LIBC_ASSERT(buffer.size() > (2 * size + 1)); const size_t half_size = buffer.size() / 2; LIBC_ASSERT((size_t)(overlap >= 0 ? overlap : -overlap) < half_size);