-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Symbol.cc and FileStream.cc: Fix -Wconversion and -Wuseless-cast on 32-bit builds #3433
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"); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+208
to
+215
|
||||||||||||||||||||||||||||||||||
| 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"); | |
| } | |
| if (position < 0) { | |
| throw Exception("Negative position not allowed"); | |
| } | |
| 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)); |
Copilot
AI
Oct 23, 2025
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.
The negative position check should occur at the beginning of the function, before any calculations are performed with position. Moving this validation earlier would fail fast and avoid unnecessary computation.
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.
Same here
| 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>) { | ||
|
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. Need to import |
||
| 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)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Do we care about 32-bit systems ?Update: Actually this PR is specifically for improving the things on 32bit systems.
The cast from
int64_ttosize_tmay truncate on 32bit