Skip to content

Commit ba177c7

Browse files
authored
[libc] Add a few missing casts (llvm#70850)
Stricter GCC warnings about implicit widening and narrowing cases necessitate additional explicit casts around some integer operations.
1 parent c81a2c0 commit ba177c7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libc/src/__support/integer_to_string.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ template <typename T, typename Fmt = radix::Dec> class IntegerToString {
213213

214214
LIBC_INLINE static char digit_char(uint8_t digit) {
215215
if (digit < 10)
216-
return '0' + digit;
217-
return (Fmt::IS_UPPERCASE ? 'A' : 'a') + (digit - 10);
216+
return '0' + static_cast<char>(digit);
217+
return (Fmt::IS_UPPERCASE ? 'A' : 'a') + static_cast<char>(digit - 10);
218218
}
219219

220220
LIBC_INLINE static void
221221
write_unsigned_number(UNSIGNED_T value,
222222
details::BackwardStringBufferWriter &sink) {
223223
for (; sink.ok() && value != 0; value /= Fmt::BASE) {
224-
const uint8_t digit(value % Fmt::BASE);
224+
const uint8_t digit(static_cast<uint8_t>(value % Fmt::BASE));
225225
sink.push(digit_char(digit));
226226
}
227227
}

libc/src/stdio/printf_core/writer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Writer final {
9393
// Takes a string, copies it into the buffer if there is space, else passes it
9494
// to the overflow mechanism to be handled separately.
9595
LIBC_INLINE int write(cpp::string_view new_string) {
96-
chars_written += new_string.size();
96+
chars_written += static_cast<int>(new_string.size());
9797
if (LIBC_LIKELY(wb->buff_cur + new_string.size() <= wb->buff_len)) {
9898
inline_memcpy(wb->buff + wb->buff_cur, new_string.data(),
9999
new_string.size());
@@ -107,7 +107,7 @@ class Writer final {
107107
// if there is space, else calls pad which will loop and call the overflow
108108
// mechanism on a secondary buffer.
109109
LIBC_INLINE int write(char new_char, size_t length) {
110-
chars_written += length;
110+
chars_written += static_cast<int>(length);
111111

112112
if (LIBC_LIKELY(wb->buff_cur + length <= wb->buff_len)) {
113113
inline_memset(wb->buff + wb->buff_cur, new_char, length);

0 commit comments

Comments
 (0)