Skip to content

Commit

Permalink
fix: explicitly cast unspecified chrono rep type
Browse files Browse the repository at this point in the history
Blackhole can handle both signed int64 and unsigned integers,
but std::chrono representation type is long long, which may
vary depending on architecture where building occurs. Thus,
it may lead to ambiguous integer promotion when it's time
to format.

This commit does explicit cast to resolve ambiguity.

This should fix #126 and #129.
  • Loading branch information
3Hren committed Jun 1, 2016
1 parent 45a00b1 commit b32339c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/formatter/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ struct visitor_t {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), rapidjson::kNullType, allocator);
}

// For `bool`, `std::int64_t`, `std::uint64_t` and `double` types.
template<typename T>
auto operator()(T value) -> void {
static_assert(
std::is_same<T, bool>::value ||
std::is_same<T, std::int64_t>::value ||
std::is_same<T, std::uint64_t>::value ||
std::is_same<T, double>::value, "type mismatch");
auto operator()(bool value) -> void {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator);
}

auto operator()(std::int64_t value) -> void {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator);
}

auto operator()(std::uint64_t value) -> void {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator);
}

auto operator()(double value) -> void {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator);
}

Expand Down Expand Up @@ -219,9 +224,10 @@ class json_t::inner_t::builder {
inner.timestamp(record.timestamp(), wr);
apply("timestamp", wr.inner.data(), wr.inner.size());
} else {
apply("timestamp", std::chrono::duration_cast<
const auto timestamp = std::chrono::duration_cast<
std::chrono::microseconds
>(record.timestamp().time_since_epoch()).count());
>(record.timestamp().time_since_epoch()).count();
apply("timestamp", static_cast<std::int64_t>(timestamp));
}
}

Expand Down

0 comments on commit b32339c

Please sign in to comment.