Skip to content

Commit 9b10755

Browse files
str_to_integer.h
1 parent ed7a9d1 commit 9b10755

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

libc/src/__support/str_to_integer.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "src/__support/str_to_num_result.h"
2626
#include "src/__support/uint128.h"
2727
#include "src/errno/libc_errno.h" // For ERANGE
28+
#include <cstddef>
2829

2930
namespace LIBC_NAMESPACE_DECL {
3031
namespace internal {
@@ -119,7 +120,7 @@ strtointeger(const char *__restrict src, int base,
119120
ResultType const abs_max =
120121
(is_positive ? cpp::numeric_limits<T>::max() : NEGATIVE_MAX);
121122
ResultType const abs_max_div_by_base =
122-
static_cast<ResultType>(abs_max / base);
123+
abs_max / static_cast<ResultType>(base);
123124

124125
while (src_cur < src_len && isalnum(src[src_cur])) {
125126
int cur_digit = b36_char_to_int(src[src_cur]);
@@ -141,17 +142,17 @@ strtointeger(const char *__restrict src, int base,
141142
result = abs_max;
142143
error_val = ERANGE;
143144
} else {
144-
result = static_cast<ResultType>(result * base);
145+
result = result * static_cast<ResultType>(base);
145146
}
146-
if (result > abs_max - cur_digit) {
147+
if (result > abs_max - static_cast<ResultType>(cur_digit)) {
147148
result = abs_max;
148149
error_val = ERANGE;
149150
} else {
150-
result = static_cast<ResultType>(result + cur_digit);
151+
result = result + static_cast<ResultType>(cur_digit);
151152
}
152153
}
153154

154-
ptrdiff_t str_len = is_number ? (src_cur) : 0;
155+
ptrdiff_t str_len = is_number ? static_cast<ptrdiff_t>(src_cur) : 0;
155156

156157
if (error_val == ERANGE) {
157158
if (is_positive || IS_UNSIGNED)

0 commit comments

Comments
 (0)