Fix undefined in printf %0$
Printf counts arguments from 1. Fixes "shift exponent -4 is negative" in PrintfTest.InvalidArgIndex. `do_get` is called with index -1 when `basic_printf_context.arg` is called with id 4294967295 when basic_printf_context::get_arg subtracts 1 from arg_index 0 in the format string "%0$d".
This commit is contained in:
parent
1bb56544ae
commit
66936d3e8f
@ -469,6 +469,8 @@ OutputIt basic_printf_context<OutputIt, Char>::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 == '.') {
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user