-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-5380: [C++] Fix memory alignment UBSan errors. #4757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,8 +211,9 @@ inline void ArrowTimestampToImpalaTimestamp(const int64_t time, Int96* impala_ti | |
| (*impala_timestamp).value[2] = (uint32_t)julian_days; | ||
|
|
||
| int64_t last_day_units = time % UnitPerDay; | ||
| int64_t* impala_last_day_nanos = reinterpret_cast<int64_t*>(impala_timestamp); | ||
| *impala_last_day_nanos = last_day_units * NanosecondsPerUnit; | ||
| auto last_day_nanos = last_day_units * NanosecondsPerUnit; | ||
| // Strage might be unaligned, so use mempcy instead of reinterpret_cast | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All even indexed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point I'll open up a follow-up PR, we must not hav good test data here or UBSan isn't foolproof, or somehow I didn't run this test properly
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait were you just commenting on my comment?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was commenting on your comment on the "strange" part :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you notice the typo? ("Strage") |
||
| std::memcpy(impala_timestamp, &last_day_nanos, sizeof(int64_t)); | ||
| } | ||
|
|
||
| constexpr int64_t kSecondsInNanos = INT64_C(1000000000); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no C++ guru, but can't you make a single method for this by templating the input type too, e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct, I think I like how the methods are now though since it is more explicit when casting and a pass-through when not. One method could certainly delegate to the other.