Skip to content

Commit

Permalink
src: fix warnings on SPrintF
Browse files Browse the repository at this point in the history
PR-URL: #32558
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
himself65 authored and addaleax committed Apr 6, 2020
1 parent 056e687 commit d3af1fe
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/debug_utils-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ struct ToStringHelper {
template <unsigned BASE_BITS,
typename T,
typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
static std::string BaseConvert(T value) {
static std::string BaseConvert(const T& value) {
auto v = static_cast<uint64_t>(value);
char ret[3 * sizeof(T)];
char* ptr = ret + 3 * sizeof(T) - 1;
*ptr = '\0';
const char* digits = "0123456789abcdef";
do {
unsigned digit = value & ((1 << BASE_BITS) - 1);
unsigned digit = v & ((1 << BASE_BITS) - 1);
*--ptr =
(BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
} while ((value >>= BASE_BITS) != 0);
} while ((v >>= BASE_BITS) != 0);
return ptr;
}
template <unsigned BASE_BITS,
Expand All @@ -56,8 +57,8 @@ std::string ToString(const T& value) {
}

template <unsigned BASE_BITS, typename T>
std::string ToBaseString(T&& value) {
return ToStringHelper::BaseConvert<BASE_BITS>(std::forward<T>(value));
std::string ToBaseString(const T& value) {
return ToStringHelper::BaseConvert<BASE_BITS>(value);
}

inline std::string SPrintFImpl(const char* format) {
Expand Down

0 comments on commit d3af1fe

Please sign in to comment.