mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 06:21:00 +00:00
Disallow leading zeros in arg-id
This commit is contained in:
parent
34030deca9
commit
e01579231d
@ -1547,6 +1547,10 @@ FMT_CONSTEXPR bool is_name_start(Char c) {
|
||||
template <typename Iterator, typename ErrorHandler>
|
||||
FMT_CONSTEXPR unsigned parse_nonnegative_int(Iterator &it, ErrorHandler &&eh) {
|
||||
assert('0' <= *it && *it <= '9');
|
||||
if (*it == '0') {
|
||||
++it;
|
||||
return 0;
|
||||
}
|
||||
unsigned value = 0;
|
||||
// Convert to unsigned to prevent a warning.
|
||||
unsigned max_int = (std::numeric_limits<int>::max)();
|
||||
@ -1574,6 +1578,10 @@ template <typename Char, typename ErrorHandler>
|
||||
FMT_CONSTEXPR unsigned parse_nonnegative_int(
|
||||
const Char *&begin, const Char *end, ErrorHandler &&eh) {
|
||||
assert(begin != end && '0' <= *begin && *begin <= '9');
|
||||
if (*begin == '0') {
|
||||
++begin;
|
||||
return 0;
|
||||
}
|
||||
unsigned value = 0;
|
||||
// Convert to unsigned to prevent a warning.
|
||||
unsigned max_int = (std::numeric_limits<int>::max)();
|
||||
|
@ -750,6 +750,7 @@ TEST(FormatterTest, ArgErrors) {
|
||||
EXPECT_THROW_MSG(format("{?}"), format_error, "invalid format string");
|
||||
EXPECT_THROW_MSG(format("{0"), format_error, "invalid format string");
|
||||
EXPECT_THROW_MSG(format("{0}"), format_error, "argument index out of range");
|
||||
EXPECT_THROW_MSG(format("{00}", 42), format_error, "invalid format string");
|
||||
|
||||
char format_str[BUFFER_SIZE];
|
||||
safe_sprintf(format_str, "{%u", INT_MAX);
|
||||
|
Loading…
Reference in New Issue
Block a user