Skip to content

Commit

Permalink
Add a comment to clarify why convert to unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 26, 2016
1 parent bb7a80b commit ae6368c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
} else {
if (is_signed) {
arg_.type = Arg::LONG_LONG;
// Convert value to unsigned type before converting to long long for
// consistency with glibc's printf even though in general it's UB:
// std::printf("%lld", -42); // prints "4294967254"
arg_.long_long_value =
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
} else {
Expand Down

0 comments on commit ae6368c

Please sign in to comment.