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 May 14, 2019
2 parents 16a442c + 2c77562 commit 2c9aa5a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
10 changes: 5 additions & 5 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,21 +656,21 @@ template <int GRISU_VERSION> struct grisu_shortest_handler {
uint64_t d = integral ? diff : diff * data::POWERS_OF_10_64[-exp];
while (remainder < d && error - remainder >= divisor &&
(remainder + divisor < d ||
d - remainder > remainder + divisor - d)) {
d - remainder >= remainder + divisor - d)) {
--buf[size - 1];
remainder += divisor;
}
return digits::done;
}
uint64_t unit = integral ? 1 : data::POWERS_OF_10_64[-exp];
uint64_t up = diff + unit; // wp_Wup
uint64_t up = (diff - 1) * unit; // wp_Wup
while (remainder < up && error - remainder >= divisor &&
(remainder + divisor < up ||
up - remainder > remainder + divisor - up)) {
up - remainder >= remainder + divisor - up)) {
--buf[size - 1];
remainder += divisor;
}
uint64_t down = diff - unit; // wp_Wdown
uint64_t down = (diff + 1) * unit; // wp_Wdown
if (remainder < down && error - remainder >= divisor &&
(remainder + divisor < down ||
down - remainder > remainder + divisor - down)) {
Expand All @@ -684,7 +684,7 @@ template <int GRISU_VERSION> struct grisu_shortest_handler {

template <typename Double, FMT_ENABLE_IF_T(sizeof(Double) == sizeof(uint64_t))>
FMT_API bool grisu_format(Double value, buffer<char>& buf, int precision,
unsigned options, int& exp) {
unsigned options, int& exp) {
FMT_ASSERT(value >= 0, "value is negative");
bool fixed = (options & grisu_options::fixed) != 0;
if (value <= 0) { // <= instead of == to silence a warning.
Expand Down
14 changes: 10 additions & 4 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ class format_string_checker {
FMT_CONSTEXPR void on_replacement_field(const Char*) {}

FMT_CONSTEXPR const Char* on_format_specs(const Char* begin, const Char*) {
context_.advance_to(begin);
advance_to(context_, begin);
return arg_id_ < NUM_ARGS ? parse_funcs_[arg_id_](context_) : begin;
}

Expand Down Expand Up @@ -3226,6 +3226,12 @@ basic_format_context<Range, Char>::arg(basic_string_view<char_type> name) {
return arg;
}

template <typename Char, typename ErrorHandler>
FMT_CONSTEXPR void advance_to(basic_parse_context<Char, ErrorHandler>& ctx,
const Char* p) {
ctx.advance_to(ctx.begin() + (p - &*ctx.begin()));
}

template <typename ArgFormatter, typename Char, typename Context>
struct format_handler : internal::error_handler {
typedef typename ArgFormatter::range range;
Expand Down Expand Up @@ -3253,15 +3259,15 @@ struct format_handler : internal::error_handler {
void on_arg_id(basic_string_view<Char> id) { arg = context.arg(id); }

void on_replacement_field(const Char* p) {
parse_context.advance_to(p);
advance_to(parse_context, p);
internal::custom_formatter<Context> f(parse_context, context);
if (!visit_format_arg(f, arg))
context.advance_to(
visit_format_arg(ArgFormatter(context, &parse_context), arg));
}

const Char* on_format_specs(const Char* begin, const Char* end) {
parse_context.advance_to(begin);
advance_to(parse_context, begin);
internal::custom_formatter<Context> f(parse_context, context);
if (visit_format_arg(f, arg)) return parse_context.begin();
basic_format_specs<Char> specs;
Expand All @@ -3272,7 +3278,7 @@ struct format_handler : internal::error_handler {
arg.type());
begin = parse_format_specs(begin, end, handler);
if (begin == end || *begin != '}') on_error("missing '}' in format string");
parse_context.advance_to(begin);
advance_to(parse_context, begin);
context.advance_to(
visit_format_arg(ArgFormatter(context, &parse_context, &specs), arg));
return begin;
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/prepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class prepared_format {
const format_part_t& part) const {
const auto view = to_string_view(format_);
const auto specification_begin = view.data() + part.end_of_argument_id;
parse_ctx.advance_to(specification_begin);
advance_to(parse_ctx, specification_begin);
}

template <typename Range, typename Context, typename Id>
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ template <typename T> class is_like_std_string {

public:
static FMT_CONSTEXPR_DECL const bool value =
!std::is_void<decltype(check<T>(FMT_NULL))>::value;
is_string<T>::value || !std::is_void<decltype(check<T>(FMT_NULL))>::value;
};

template <typename Char>
Expand Down

0 comments on commit 2c9aa5a

Please sign in to comment.