Skip to content

Commit

Permalink
fix more UBSAN error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhli1142015 committed Apr 28, 2024
1 parent b21f819 commit f549b6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion velox/functions/sparksql/DateTimeFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ struct MicrosToTimestampFunction {
FOLLY_ALWAYS_INLINE void call(
out_type<Timestamp>& result,
const TInput micros) {
result = Timestamp::fromMicros(micros);
result = Timestamp::fromMicrosNoError(micros);
}
};

Expand Down
15 changes: 15 additions & 0 deletions velox/type/Timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ struct Timestamp {
return Timestamp(second, nano);
}

static Timestamp fromMicrosNoError(int64_t micros)
#if defined(__has_feature)
#if __has_feature(__address_sanitizer__)
__attribute__((__no_sanitize__("signed-integer-overflow")))
#endif
#endif
{
if (micros >= 0 || micros % 1'000'000 == 0) {
return Timestamp(micros / 1'000'000, (micros % 1'000'000) * 1'000);
}
auto second = micros / 1'000'000 - 1;
auto nano = ((micros - second * 1'000'000) % 1'000'000) * 1'000;
return Timestamp(second, nano);
}

static Timestamp fromNanos(int64_t nanos) {
if (nanos >= 0 || nanos % 1'000'000'000 == 0) {
return Timestamp(nanos / 1'000'000'000, nanos % 1'000'000'000);
Expand Down

0 comments on commit f549b6c

Please sign in to comment.