diff --git a/format.cc b/format.cc index 8965aca2..90848b7e 100644 --- a/format.cc +++ b/format.cc @@ -173,7 +173,7 @@ int parse_nonnegative_int(const Char *&s) { value = new_value; } while ('0' <= *s && *s <= '9'); if (value > INT_MAX) - throw fmt::FormatError("number is too big in format"); + throw fmt::FormatError("number is too big"); return value; } @@ -212,7 +212,7 @@ class WidthHandler : public fmt::internal::ArgVisitor { width = 0 - width; } if (width > INT_MAX) - throw fmt::FormatError("number is too big in format"); + throw fmt::FormatError("number is too big"); return static_cast(width); } }; @@ -227,7 +227,7 @@ class PrecisionHandler : template int visit_any_int(T value) { if (!IntChecker::is_signed>::fits_in_int(value)) - throw fmt::FormatError("number is too big in format"); + throw fmt::FormatError("number is too big"); return static_cast(value); } }; @@ -1173,7 +1173,7 @@ const Char *fmt::BasicFormatter::format( throw FormatError("precision is not integer"); } if (value > INT_MAX) - throw FormatError("number is too big in format"); + throw FormatError("number is too big"); spec.precision_ = static_cast(value); } else { throw FormatError("missing precision in format"); diff --git a/test/format-test.cc b/test/format-test.cc index 9355ac25..c434efdb 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -619,11 +619,9 @@ TEST(FormatterTest, ArgErrors) { "argument index is out of range in format"); safe_sprintf(format_str, "{%u", INT_MAX + 1u); - EXPECT_THROW_MSG(format(format_str), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str), FormatError, "number is too big"); safe_sprintf(format_str, "{%u}", INT_MAX + 1u); - EXPECT_THROW_MSG(format(format_str), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str), FormatError, "number is too big"); } TEST(FormatterTest, AutoArgIndex) { @@ -897,20 +895,16 @@ TEST(FormatterTest, Width) { char format_str[BUFFER_SIZE]; safe_sprintf(format_str, "{0:%u", UINT_MAX); increment(format_str + 3); - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); std::size_t size = std::strlen(format_str); format_str[size] = '}'; format_str[size + 1] = 0; - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); safe_sprintf(format_str, "{0:%u", INT_MAX + 1u); - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); safe_sprintf(format_str, "{0:%u}", INT_MAX + 1u); - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); EXPECT_EQ(" -42", format("{0:4}", -42)); EXPECT_EQ(" 42", format("{0:5}", 42u)); EXPECT_EQ(" -42", format("{0:6}", -42l)); @@ -929,20 +923,16 @@ TEST(FormatterTest, Precision) { char format_str[BUFFER_SIZE]; safe_sprintf(format_str, "{0:.%u", UINT_MAX); increment(format_str + 4); - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); std::size_t size = std::strlen(format_str); format_str[size] = '}'; format_str[size + 1] = 0; - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); safe_sprintf(format_str, "{0:.%u", INT_MAX + 1u); - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); safe_sprintf(format_str, "{0:.%u}", INT_MAX + 1u); - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); EXPECT_THROW_MSG(format("{0:.", 0), FormatError, "missing precision in format"); @@ -1003,17 +993,14 @@ TEST(FormatterTest, RuntimePrecision) { char format_str[BUFFER_SIZE]; safe_sprintf(format_str, "{0:.{%u", UINT_MAX); increment(format_str + 5); - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); std::size_t size = std::strlen(format_str); format_str[size] = '}'; format_str[size + 1] = 0; - EXPECT_THROW_MSG(format(format_str, 0), FormatError, - "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); format_str[size + 1] = '}'; format_str[size + 2] = 0; - EXPECT_THROW_MSG(format(format_str, 0), - FormatError, "number is too big in format"); + EXPECT_THROW_MSG(format(format_str, 0), FormatError, "number is too big"); EXPECT_THROW_MSG(format("{0:.{", 0), FormatError, "invalid format string"); @@ -1029,16 +1016,16 @@ TEST(FormatterTest, RuntimePrecision) { EXPECT_THROW_MSG(format("{0:.{1}}", 0, -1), FormatError, "negative precision in format"); EXPECT_THROW_MSG(format("{0:.{1}}", 0, (INT_MAX + 1u)), - FormatError, "number is too big in format"); + FormatError, "number is too big"); EXPECT_THROW_MSG(format("{0:.{1}}", 0, -1l), FormatError, "negative precision in format"); if (sizeof(long) > sizeof(int)) { long value = INT_MAX; EXPECT_THROW_MSG(format("{0:.{1}}", 0, (value + 1)), - FormatError, "number is too big in format"); + FormatError, "number is too big"); } EXPECT_THROW_MSG(format("{0:.{1}}", 0, (INT_MAX + 1ul)), - FormatError, "number is too big in format"); + FormatError, "number is too big"); EXPECT_THROW_MSG(format("{0:.{1}}", 0, '0'), FormatError, "precision is not integer"); diff --git a/test/printf-test.cc b/test/printf-test.cc index d2d89821..8c86ede8 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -79,31 +79,31 @@ TEST(PrintfTest, AutomaticArgIndexing) { TEST(PrintfTest, NumberIsTooBigInArgIndex) { EXPECT_THROW_MSG(fmt::sprintf(format("%{}$", BIG_NUM)), - FormatError, "number is too big in format"); + FormatError, "number is too big"); EXPECT_THROW_MSG(fmt::sprintf(format("%{}$d", BIG_NUM)), - FormatError, "number is too big in format"); + FormatError, "number is too big"); } TEST(PrintfTest, SwitchArgIndexing) { EXPECT_THROW_MSG(fmt::sprintf("%1$d%", 1, 2), FormatError, "invalid format string"); EXPECT_THROW_MSG(fmt::sprintf(format("%1$d%{}d", BIG_NUM), 1, 2), - FormatError, "number is too big in format"); + FormatError, "number is too big"); EXPECT_THROW_MSG(fmt::sprintf("%1$d%d", 1, 2), FormatError, "cannot switch from manual to automatic argument indexing"); EXPECT_THROW_MSG(fmt::sprintf("%d%1$", 1, 2), FormatError, "invalid format string"); EXPECT_THROW_MSG(fmt::sprintf(format("%d%{}$d", BIG_NUM), 1, 2), - FormatError, "number is too big in format"); + FormatError, "number is too big"); EXPECT_THROW_MSG(fmt::sprintf("%d%1$d", 1, 2), FormatError, "cannot switch from automatic to manual argument indexing"); // Indexing errors override width errors. EXPECT_THROW_MSG(fmt::sprintf(format("%d%1${}d", BIG_NUM), 1, 2), - FormatError, "number is too big in format"); + FormatError, "number is too big"); EXPECT_THROW_MSG(fmt::sprintf(format("%1$d%{}d", BIG_NUM), 1, 2), - FormatError, "number is too big in format"); + FormatError, "number is too big"); } TEST(PrintfTest, InvalidArgIndex) { @@ -117,7 +117,7 @@ TEST(PrintfTest, InvalidArgIndex) { EXPECT_THROW_MSG(fmt::sprintf("%2$", 42), FormatError, "invalid format string"); EXPECT_THROW_MSG(fmt::sprintf(format("%{}$d", BIG_NUM), 42), - FormatError, "number is too big in format"); + FormatError, "number is too big"); } TEST(PrintfTest, DefaultAlignRight) { @@ -207,9 +207,9 @@ TEST(PrintfTest, Width) { "unknown format code '-' for integer"); EXPECT_THROW_MSG(fmt::sprintf(format("%{}d", BIG_NUM), 42), - FormatError, "number is too big in format"); + FormatError, "number is too big"); EXPECT_THROW_MSG(fmt::sprintf(format("%1${}d", BIG_NUM), 42), - FormatError, "number is too big in format"); + FormatError, "number is too big"); } TEST(PrintfTest, DynamicWidth) { @@ -220,7 +220,7 @@ TEST(PrintfTest, DynamicWidth) { EXPECT_THROW_MSG(fmt::sprintf("%*d"), FormatError, "argument index is out of range in format"); EXPECT_THROW_MSG(fmt::sprintf("%*d", BIG_NUM, 42), FormatError, - "number is too big in format"); + "number is too big"); } TEST(PrintfTest, IntPrecision) { @@ -267,11 +267,11 @@ TEST(PrintfTest, DynamicPrecision) { EXPECT_THROW_MSG(fmt::sprintf("%.*d"), FormatError, "argument index is out of range in format"); EXPECT_THROW_MSG(fmt::sprintf("%.*d", BIG_NUM, 42), FormatError, - "number is too big in format"); + "number is too big"); if (sizeof(fmt::LongLong) != sizeof(int)) { fmt::LongLong prec = static_cast(INT_MIN) - 1; EXPECT_THROW_MSG(fmt::sprintf("%.*d", prec, 42), FormatError, - "number is too big in format"); + "number is too big"); } }