diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 18f8d121..6c7e328f 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -469,6 +469,8 @@ OutputIt basic_printf_context::format() { // Parse argument index, flags and width. unsigned arg_index = parse_header(it, end, specs); + if (arg_index == 0) + on_error("argument index 0 is out of range"); // Parse precision. if (it != end && *it == '.') { diff --git a/test/core-test.cc b/test/core-test.cc index 84d2b9eb..76612b99 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -103,7 +103,7 @@ template struct mock_buffer : buffer { TEST(BufferTest, Ctor) { { mock_buffer buffer; - EXPECT_EQ(nullptr, &buffer[0]); + EXPECT_EQ(nullptr, buffer.data()); EXPECT_EQ(static_cast(0), buffer.size()); EXPECT_EQ(static_cast(0), buffer.capacity()); } diff --git a/test/printf-test.cc b/test/printf-test.cc index cd9950d1..f158a627 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -112,7 +112,7 @@ TEST(PrintfTest, SwitchArgIndexing) { TEST(PrintfTest, InvalidArgIndex) { EXPECT_THROW_MSG(test_sprintf("%0$d", 42), format_error, - "argument index out of range"); + "argument index 0 is out of range"); EXPECT_THROW_MSG(test_sprintf("%2$d", 42), format_error, "argument index out of range"); EXPECT_THROW_MSG(test_sprintf(format("%{}$d", INT_MAX), 42), format_error, @@ -337,7 +337,9 @@ template void TestLength(const char* length_spec) { TestLength(length_spec, -42); TestLength(length_spec, min); TestLength(length_spec, max); - TestLength(length_spec, static_cast(min) - 1); + long long long_long_min = std::numeric_limits::min(); + if (static_cast(min) > long_long_min) + TestLength(length_spec, static_cast(min) - 1); unsigned long long long_long_max = max_value(); if (static_cast(max) < long_long_max) TestLength(length_spec, static_cast(max) + 1);