Skip to content

Commit 3a9667c

Browse files
Fix adjust to be ptrdiff_t
As per: #127523 (comment)
1 parent 7a71ad5 commit 3a9667c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

libc/src/string/memory_utils/utils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
1818
#include "src/__support/macros/properties/architectures.h"
1919

20+
#include <cstddef>
2021
#include <stddef.h> // size_t
2122
#include <stdint.h> // intptr_t / uintptr_t / INT32_MAX / INT32_MIN
2223

@@ -293,11 +294,11 @@ LIBC_INLINE void store64_aligned(uint64_t value, Ptr dst, size_t offset) {
293294
// Advances the pointers p1 and p2 by offset bytes and decrease count by the
294295
// same amount.
295296
template <typename T1, typename T2>
296-
LIBC_INLINE void adjust(uintptr_t offset, T1 *__restrict &p1,
297+
LIBC_INLINE void adjust(ptrdiff_t offset, T1 *__restrict &p1,
297298
T2 *__restrict &p2, size_t &count) {
298299
p1 += offset;
299300
p2 += offset;
300-
count -= offset;
301+
count -= static_cast<size_t>(offset);
301302
}
302303

303304
// Advances p1 and p2 so p1 gets aligned to the next SIZE bytes boundary
@@ -306,7 +307,7 @@ LIBC_INLINE void adjust(uintptr_t offset, T1 *__restrict &p1,
306307
template <size_t SIZE, typename T1, typename T2>
307308
void align_p1_to_next_boundary(T1 *__restrict &p1, T2 *__restrict &p2,
308309
size_t &count) {
309-
adjust(distance_to_next_aligned<SIZE>(p1), p1, p2, count);
310+
adjust(static_cast<ptrdiff_t>(distance_to_next_aligned<SIZE>(p1)), p1, p2, count);
310311
p1 = assume_aligned<SIZE>(p1);
311312
}
312313

libc/test/src/string/memory_utils/utils_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ TEST(LlvmLibcUtilsTest, Adjust2) {
5151
auto *p1 = &a;
5252
auto *p2 = &b;
5353
size_t size = base_size;
54-
adjust(I, p1, p2, size);
54+
adjust(static_cast<ptrdiff_t>(I), p1, p2, size);
5555
EXPECT_EQ(intptr_t(p1), intptr_t(&a + I));
5656
EXPECT_EQ(intptr_t(p2), intptr_t(&b + I));
5757
EXPECT_EQ(size, base_size - I);

0 commit comments

Comments
 (0)