Skip to content

[libc] Add a few missing casts #70850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libc/src/__support/integer_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ template <typename T, typename Fmt = radix::Dec> class IntegerToString {

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

LIBC_INLINE static void
write_unsigned_number(UNSIGNED_T value,
details::BackwardStringBufferWriter &sink) {
for (; sink.ok() && value != 0; value /= Fmt::BASE) {
const uint8_t digit(value % Fmt::BASE);
const uint8_t digit(static_cast<uint8_t>(value % Fmt::BASE));
sink.push(digit_char(digit));
}
}
Expand Down
4 changes: 2 additions & 2 deletions libc/src/stdio/printf_core/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Writer final {
// Takes a string, copies it into the buffer if there is space, else passes it
// to the overflow mechanism to be handled separately.
LIBC_INLINE int write(cpp::string_view new_string) {
chars_written += new_string.size();
chars_written += static_cast<int>(new_string.size());
if (LIBC_LIKELY(wb->buff_cur + new_string.size() <= wb->buff_len)) {
inline_memcpy(wb->buff + wb->buff_cur, new_string.data(),
new_string.size());
Expand All @@ -107,7 +107,7 @@ class Writer final {
// if there is space, else calls pad which will loop and call the overflow
// mechanism on a secondary buffer.
LIBC_INLINE int write(char new_char, size_t length) {
chars_written += length;
chars_written += static_cast<int>(length);

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