diff --git a/format.cc b/format.cc index 2aa38bc0..995e5727 100644 --- a/format.cc +++ b/format.cc @@ -328,11 +328,10 @@ class ArgConverter : public fmt::internal::ArgVisitor, 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: + // glibc's printf doesn't sign extend arguments of smaller types: // std::printf("%lld", -42); // prints "4294967254" - arg_.long_long_value = - static_cast::Type>(value); + // but we don't have to do the same because it's a UB. + arg_.long_long_value = value; } else { arg_.type = Arg::ULONG_LONG; arg_.ulong_long_value = diff --git a/test/printf-test.cc b/test/printf-test.cc index 12b50cdf..5607aa6a 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -306,8 +306,8 @@ void TestLength(const char *length_spec, U value) { } using fmt::internal::MakeUnsigned; if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) { - signed_value = unsigned_value = - static_cast::Type>(value); + signed_value = value; + unsigned_value = static_cast::Type>(value); } else { signed_value = static_cast::Type>(value); unsigned_value = static_cast::Type>(value);