Throw exception in parse_nonnegative_int if the number is too big.
This commit is contained in:
+4
-2
@@ -619,7 +619,8 @@ 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, "invalid format string");
|
||||
EXPECT_THROW_MSG(format(format_str), FormatError,
|
||||
"number is too big in format");
|
||||
safe_sprintf(format_str, "{%u}", INT_MAX + 1u);
|
||||
EXPECT_THROW_MSG(format(format_str), FormatError,
|
||||
"number is too big in format");
|
||||
@@ -1002,7 +1003,8 @@ 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, "invalid format string");
|
||||
EXPECT_THROW_MSG(format(format_str, 0), FormatError,
|
||||
"number is too big in format");
|
||||
std::size_t size = std::strlen(format_str);
|
||||
format_str[size] = '}';
|
||||
format_str[size + 1] = 0;
|
||||
|
||||
+11
-1
@@ -79,7 +79,7 @@ TEST(PrintfTest, AutomaticArgIndexing) {
|
||||
|
||||
TEST(PrintfTest, NumberIsTooBigInArgIndex) {
|
||||
EXPECT_THROW_MSG(fmt::sprintf(format("%{}$", BIG_NUM)),
|
||||
FormatError, "invalid format string");
|
||||
FormatError, "number is too big in format");
|
||||
EXPECT_THROW_MSG(fmt::sprintf(format("%{}$d", BIG_NUM)),
|
||||
FormatError, "number is too big in format");
|
||||
}
|
||||
@@ -429,3 +429,13 @@ TEST(PrintfTest, Pointer) {
|
||||
TEST(PrintfTest, Location) {
|
||||
// TODO: test %n
|
||||
}
|
||||
|
||||
#if FMT_USE_FILE_DESCRIPTORS
|
||||
TEST(PrintfTest, Examples) {
|
||||
const char *weekday = "Thursday";
|
||||
const char *month = "August";
|
||||
int day = 21;
|
||||
EXPECT_WRITE(stdout, fmt::printf("%1$s, %3$d %2$s", weekday, month, day),
|
||||
"Thursday, 21 August");
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user