-
Notifications
You must be signed in to change notification settings - Fork 0
3433: Symbol.cc and FileStream.cc: Fix -Wconversion and -Wuseless-cast on 32-bit builds #12
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,8 +205,15 @@ class BufferCopyInInputStream : public SeekableInputStream { | |
| void seek(int64_t position) final { | ||
| // BufferCopyIn::seek is relative to byteCount_, whereas position is | ||
| // absolute. | ||
| in_->seek(position - byteCount_ - available_); | ||
| byteCount_ = position; | ||
| int64_t offset = position - static_cast<int64_t>(byteCount_) - static_cast<int64_t>(available_); | ||
| if (offset < 0) { | ||
| throw Exception("Negative offset in seek"); | ||
| } | ||
| in_->seek(static_cast<size_t>(offset)); | ||
| if (position < 0) { | ||
| throw Exception("Negative position not allowed"); | ||
| } | ||
| byteCount_ = static_cast<size_t>(position); | ||
|
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. Similarly, casting 🤖 React with 👍 or 👎 to let us know if the comment was useful.
Owner
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. value:useful; category:bug; feedback:prevented an undesired truncation of int64_t to int32_t on 32bit systems. |
||
| available_ = 0; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,7 +88,12 @@ Symbol Symbol::enumAdjustSymbol(const NodePtr &writer, const NodePtr &reader) { | |
| adj.push_back(static_cast<int>(-pos)); | ||
| err.push_back(s); | ||
| } else { | ||
| adj.push_back(static_cast<int>(it - rs.begin())); | ||
| auto index = it - rs.begin(); | ||
| if constexpr (std::is_same_v<decltype(index), int>) { | ||
|
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.
🤖 React with 👍 or 👎 to let us know if the comment was useful.
Owner
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. value:useful; category:bug; feedback:It seems |
||
| adj.push_back(index); // 32-bit: already int | ||
| } else { | ||
| adj.push_back(static_cast<int>(index)); // 64-bit: long to int | ||
| } | ||
| } | ||
| } | ||
| return Symbol(Kind::EnumAdjust, make_pair(adj, err)); | ||
|
|
||
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.
On 32-bit builds, casting 64-bit
offsettosize_tcan truncate for large values; consider validating thatoffsetfits insize_tbefore callingin_->seekto avoid incorrect seek.🤖 React with 👍 or 👎 to let us know if the comment was useful.
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.
value:useful; category:bug; feedback:prevented an undesired truncation of int64_t to int32_t on 32bit systems.