From fad81818420e74797b8c22c2c2ac116b2a75536a Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 28 Jul 2016 16:11:47 +1000 Subject: [PATCH] format: allow undersize integers for conversion --- format.ipp | 4 ++-- test/format.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/format.ipp b/format.ipp index 6efc8da1..42ac2461 100644 --- a/format.ipp +++ b/format.ipp @@ -729,8 +729,8 @@ namespace util { namespace format { namespace detail { if (spec.k != (std::is_unsigned::value ? specifier::kind::UNSIGNED : specifier::kind::SIGNED)) throw conversion_error ("invalid conversion specifier for integer value"); - if (spec.length != sizeof (ValueT)) - throw length_error ("incorrect value size"); + if (sizeof (ValueT) > spec.length) + throw length_error ("overlength value parameter"); const auto numerals = digits (t, spec.base); const auto characters = numerals + (spec.positive_char ? 1 : 0); diff --git a/test/format.cpp b/test/format.cpp index 119d84c0..0628ea58 100644 --- a/test/format.cpp +++ b/test/format.cpp @@ -167,7 +167,7 @@ main (void) CHECK_THROW("%i", conversion_error, nullptr); CHECK_THROW("%hhi", length_error, (long long)1); - CHECK_THROW("%lli", length_error, (signed char)1); + //CHECK_THROW("%lli", length_error, (signed char)1); CHECK_THROW("%u", conversion_error, 1.); CHECK_THROW("%u", conversion_error, "foo"); @@ -176,7 +176,7 @@ main (void) CHECK_THROW("%u", conversion_error, nullptr); CHECK_THROW("%hhu", length_error, (unsigned long long)1); - CHECK_THROW("%llu", length_error, (unsigned char)1); + //CHECK_THROW("%llu", length_error, (unsigned char)1); CHECK_THROW("%f", conversion_error, 1u); CHECK_THROW("%f", conversion_error, "foo");