mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
Sign extend arguments of smaller types passed to %ll? (#265)
This commit is contained in:
parent
ae6368c985
commit
7ee287d3d9
@ -328,11 +328,10 @@ 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:
|
||||
// glibc's printf doesn't sign extend arguments of smaller types:
|
||||
// std::printf("%lld", -42); // prints "4294967254"
|
||||
arg_.long_long_value =
|
||||
static_cast<typename fmt::internal::MakeUnsigned<U>::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 =
|
||||
|
@ -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<typename MakeUnsigned<unsigned>::Type>(value);
|
||||
signed_value = value;
|
||||
unsigned_value = static_cast<typename MakeUnsigned<unsigned>::Type>(value);
|
||||
} else {
|
||||
signed_value = static_cast<typename MakeSigned<T>::Type>(value);
|
||||
unsigned_value = static_cast<typename MakeUnsigned<T>::Type>(value);
|
||||
|
Loading…
Reference in New Issue
Block a user