Skip to content

Commit 2376dc8

Browse files
maybe done
1 parent 8bd8007 commit 2376dc8

File tree

7 files changed

+16
-17
lines changed

7 files changed

+16
-17
lines changed

libc/src/stdio/printf_core/parser.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ template <typename T> using int_type_of_v = typename int_type_of<T>::type;
5757
if (!temp.has_value()) { \
5858
section.has_conv = false; \
5959
} else { \
60-
dst = cpp::bit_cast<int_type_of_v<arg_type>>(temp.value()); \
60+
dst = static_cast<decltype(dst)>(cpp::bit_cast<int_type_of_v<arg_type>>(temp.value())); \
6161
} \
6262
}
6363
#else
@@ -130,7 +130,7 @@ template <typename ArgProvider> class Parser {
130130
} else if (internal::isdigit(str[cur_pos])) {
131131
auto result = internal::strtointeger<int>(str + cur_pos, 10);
132132
section.min_width = result.value;
133-
cur_pos = cur_pos + result.parsed_len;
133+
cur_pos = cur_pos + static_cast<size_t>(result.parsed_len);
134134
}
135135
if (section.min_width < 0) {
136136
section.min_width =
@@ -153,7 +153,7 @@ template <typename ArgProvider> class Parser {
153153
} else if (internal::isdigit(str[cur_pos])) {
154154
auto result = internal::strtointeger<int>(str + cur_pos, 10);
155155
section.precision = result.value;
156-
cur_pos = cur_pos + result.parsed_len;
156+
cur_pos = cur_pos + static_cast<size_t>(result.parsed_len);
157157
}
158158
}
159159

@@ -356,7 +356,7 @@ template <typename ArgProvider> class Parser {
356356
}
357357
if (internal::isdigit(str[*local_pos])) {
358358
const auto result = internal::strtointeger<int>(str + *local_pos, 10);
359-
*local_pos += result.parsed_len;
359+
*local_pos += static_cast<size_t>(result.parsed_len);
360360
return {lm, static_cast<size_t>(cpp::max(0, result.value))};
361361
}
362362
return {lm, 0};
@@ -405,10 +405,10 @@ template <typename ArgProvider> class Parser {
405405
LIBC_INLINE size_t parse_index(size_t *local_pos) {
406406
if (internal::isdigit(str[*local_pos])) {
407407
auto result = internal::strtointeger<int>(str + *local_pos, 10);
408-
size_t index = result.value;
409-
if (str[*local_pos + result.parsed_len] != '$')
408+
size_t index = static_cast<size_t>(result.value);
409+
if (str[*local_pos + static_cast<size_t>(result.parsed_len)] != '$')
410410
return 0;
411-
*local_pos = 1 + result.parsed_len + *local_pos;
411+
*local_pos = static_cast<size_t>(1 + result.parsed_len) + *local_pos;
412412
return index;
413413
}
414414
return 0;

libc/src/stdio/scanf_core/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ template <typename ArgProvider> class Parser {
240240
size_t index = static_cast<size_t>(result.value);
241241
if (str[*local_pos + static_cast<size_t>(result.parsed_len)] != '$')
242242
return 0;
243-
*local_pos = 1 + result.parsed_len + *local_pos;
243+
*local_pos = static_cast<size_t>(1 + result.parsed_len) + *local_pos;
244244
return index;
245245
}
246246
return 0;

libc/src/string/memory_utils/utils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include <stddef.h> // size_t
2121
#include <stdint.h> // intptr_t / uintptr_t / INT32_MAX / INT32_MIN
22-
#include <sys/_types/_uintptr_t.h>
2322

2423
namespace LIBC_NAMESPACE_DECL {
2524

@@ -264,7 +263,7 @@ LIBC_INLINE void store_aligned(ValueType value, Ptr dst) {
264263
static_assert(sizeof(ValueType) >= (sizeof(T) + ... + sizeof(TS)));
265264
constexpr size_t SHIFT = sizeof(T) * 8;
266265
if constexpr (Endian::IS_LITTLE) {
267-
store<T>(assume_aligned<sizeof(T)>(dst), value & ~T(0));
266+
store<T>(assume_aligned<sizeof(T)>(dst), T(value & T(~0)));
268267
if constexpr (sizeof...(TS) > 0)
269268
store_aligned<ValueType, TS...>(value >> SHIFT, dst + sizeof(T));
270269
} else if constexpr (Endian::IS_BIG) {

libc/test/src/stdio/printf_core/parser_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeComplexParsing) {
546546
expected9.raw_string = {str + 41, 7};
547547
expected9.min_width = 1;
548548
expected9.precision = 1;
549-
expected9.conv_val_raw = arg1;
549+
expected9.conv_val_raw = static_cast<LIBC_NAMESPACE::fputil::FPBits<double>::StorageType>(arg1);
550550
expected9.conv_name = 'c';
551551

552552
EXPECT_PFORMAT_EQ(expected9, format_arr[9]);
@@ -566,14 +566,14 @@ TEST(LlvmLibcPrintfParserTest, IndexModeGapCheck) {
566566

567567
expected0.has_conv = true;
568568
expected0.raw_string = {str, 4};
569-
expected0.conv_val_raw = arg1;
569+
expected0.conv_val_raw = static_cast<LIBC_NAMESPACE::fputil::FPBits<double>::StorageType>(arg1);
570570
expected0.conv_name = 'd';
571571

572572
EXPECT_PFORMAT_EQ(expected0, format_arr[0]);
573573

574574
expected1.has_conv = true;
575575
expected1.raw_string = {str + 4, 4};
576-
expected1.conv_val_raw = arg2;
576+
expected1.conv_val_raw = static_cast<LIBC_NAMESPACE::fputil::FPBits<double>::StorageType>(arg2);
577577
expected1.conv_name = 'd';
578578

579579
EXPECT_PFORMAT_EQ(expected1, format_arr[1]);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ TYPED_TEST(LlvmLibcOpTest, Memset, MemsetImplementations) {
174174
static constexpr auto HeadTailImpl = SetAdaptor<Impl::head_tail>;
175175
Buffer DstBuffer(2 * kSize);
176176
for (size_t size = kSize; size < 2 * kSize; ++size) {
177-
const char value = size % 10;
177+
const uint8_t value = size % 10;
178178
auto dst = DstBuffer.span().subspan(0, size);
179179
ASSERT_TRUE(CheckMemset<HeadTailImpl>(dst, value, size));
180180
}
@@ -185,7 +185,7 @@ TYPED_TEST(LlvmLibcOpTest, Memset, MemsetImplementations) {
185185
static constexpr auto LoopImpl = SetAdaptor<Impl::loop_and_tail>;
186186
Buffer DstBuffer(3 * kSize);
187187
for (size_t size = kSize; size < 3 * kSize; ++size) {
188-
const char value = size % 10;
188+
const uint8_t value = size % 10;
189189
auto dst = DstBuffer.span().subspan(0, size);
190190
ASSERT_TRUE((CheckMemset<LoopImpl>(dst, value, size)));
191191
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ TEST(LlvmLibcUtilsTest, DistanceToAlignDown) {
4747
TEST(LlvmLibcUtilsTest, Adjust2) {
4848
char a, b;
4949
const size_t base_size = 10;
50-
for (ptrdiff_t I = -2; I < 2; ++I) {
50+
for (uintptr_t I = 0; I < 4; ++I) {
5151
auto *p1 = &a;
5252
auto *p2 = &b;
5353
size_t size = base_size;

libc/test/src/strings/bcopy_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ TEST(LlvmLibcBcopyTest, SizeSweep) {
8787
Randomize(Buffer);
8888
for (int Size = 0; Size < kMaxSize; ++Size)
8989
for (int Overlap = -1; Overlap < Size;) {
90-
ASSERT_TRUE(CheckMemmove<Adaptor>(Buffer, Size, Overlap));
90+
ASSERT_TRUE(CheckMemmove<Adaptor>(Buffer, static_cast<size_t>(Size), Overlap));
9191
// Prevent quadratic behavior by skipping offset above kDenseOverlap.
9292
if (Overlap > kDenseOverlap)
9393
Overlap *= 2;

0 commit comments

Comments
 (0)