format: allow undersize integers for conversion

This commit is contained in:
Danny Robson 2016-07-28 16:11:47 +10:00
parent a40e09ed97
commit fad8181842
2 changed files with 4 additions and 4 deletions

View File

@ -729,8 +729,8 @@ namespace util { namespace format { namespace detail {
if (spec.k != (std::is_unsigned<ValueT>::value ? specifier::kind::UNSIGNED : specifier::kind::SIGNED)) if (spec.k != (std::is_unsigned<ValueT>::value ? specifier::kind::UNSIGNED : specifier::kind::SIGNED))
throw conversion_error ("invalid conversion specifier for integer value"); throw conversion_error ("invalid conversion specifier for integer value");
if (spec.length != sizeof (ValueT)) if (sizeof (ValueT) > spec.length)
throw length_error ("incorrect value size"); throw length_error ("overlength value parameter");
const auto numerals = digits (t, spec.base); const auto numerals = digits (t, spec.base);
const auto characters = numerals + (spec.positive_char ? 1 : 0); const auto characters = numerals + (spec.positive_char ? 1 : 0);

View File

@ -167,7 +167,7 @@ main (void)
CHECK_THROW("%i", conversion_error, nullptr); CHECK_THROW("%i", conversion_error, nullptr);
CHECK_THROW("%hhi", length_error, (long long)1); 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, 1.);
CHECK_THROW("%u", conversion_error, "foo"); CHECK_THROW("%u", conversion_error, "foo");
@ -176,7 +176,7 @@ main (void)
CHECK_THROW("%u", conversion_error, nullptr); CHECK_THROW("%u", conversion_error, nullptr);
CHECK_THROW("%hhu", length_error, (unsigned long long)1); 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, 1u);
CHECK_THROW("%f", conversion_error, "foo"); CHECK_THROW("%f", conversion_error, "foo");