Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldreik committed Apr 21, 2019
2 parents 99b2e08 + bd516e3 commit e37d7db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,7 @@ It grisu2_prettify(const char* digits, int size, int exp, It it,
*it++ = static_cast<Char>(params.upper ? 'E' : 'e');
return write_exponent<Char>(exp, it);
}
const int exp_threshold = 21;
if (size <= full_exp && full_exp <= exp_threshold) {
if (size <= full_exp) {
// 1234e7 -> 12340000000[.0+]
it = copy_str<Char>(digits, digits + size, it);
it = std::fill_n(it, full_exp - size, static_cast<Char>('0'));
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class printf_precision_handler : public function<int> {
int operator()(T value) {
if (!int_checker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
FMT_THROW(format_error("number is too big"));
return static_cast<int>(value);
return (std::max)(static_cast<int>(value), 0);
}

template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
Expand Down
6 changes: 5 additions & 1 deletion test/printf-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ TEST(PrintfTest, CheckFormatStringRegression) {
check_format_string_regression("%c%s", 'x', "");
}

TEST(PrintfTest, FixedLargeExponent) {
EXPECT_EQ("1000000000000000000000", fmt::sprintf("%.*f", -13, 1e21));
}

TEST(PrintfTest, VSPrintfMakeArgsExample) {
fmt::format_arg_store<fmt::printf_context, int, const char*> as{42,
"something"};
Expand Down Expand Up @@ -599,7 +603,7 @@ std::string custom_format(const char* format_str, const Args&... args) {
return custom_vformat(format_str, va);
}

TEST(CustomFormatterTest, Format) {
TEST(PrintfTest, CustomFormat) {
EXPECT_EQ("0.00", custom_format("%.2f", -.00001));
EXPECT_EQ("0.00", custom_format("%.2f", .00001));
EXPECT_EQ("1.00", custom_format("%.2f", 1.00001));
Expand Down

0 comments on commit e37d7db

Please sign in to comment.