From 87cb2935f8150d9190e4298ee00309f562cb2803 Mon Sep 17 00:00:00 2001 From: vitaut Date: Fri, 1 May 2015 06:55:26 -0700 Subject: [PATCH] Test and fix handling of exactly MAX_PACKED_ARGS arguments --- format.h | 2 +- test/format-test.cc | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/format.h b/format.h index 8ce0116b..9e8c317f 100644 --- a/format.h +++ b/format.h @@ -2665,7 +2665,7 @@ inline void set_types(Value *, const Args & ...) { // argument that marks the end of the list. template struct ArgArraySize { - enum { VALUE = N + (N == 0 || N > ArgList::MAX_PACKED_ARGS ? 1 : 0) }; + enum { VALUE = N + (N == 0 || N >= ArgList::MAX_PACKED_ARGS ? 1 : 0) }; }; } } diff --git a/test/format-test.cc b/test/format-test.cc index d3bb023b..c75d31d2 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -574,6 +574,10 @@ TEST(FormatterTest, ManyArgs) { FormatError, "argument index out of range"); EXPECT_THROW_MSG(TestFormat<21>::format("{21}"), FormatError, "argument index out of range"); + enum { MAX_PACKED_ARGS = fmt::ArgList::MAX_PACKED_ARGS }; + std::string format_str = fmt::format("{{{}}}", MAX_PACKED_ARGS + 1); + EXPECT_THROW_MSG(TestFormat::format(format_str), + FormatError, "argument index out of range"); } #endif