Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lang/c++/impl/FileStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Copy link
Copy Markdown

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 offset to size_t can truncate for large values; consider validating that offset fits in size_t before calling in_->seek to avoid incorrect seek.

🤖 React with 👍 or 👎 to let us know if the comment was useful.

Copy link
Copy Markdown
Owner Author

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.

if (position < 0) {
throw Exception("Negative position not allowed");
}
byteCount_ = static_cast<size_t>(position);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, casting position (int64_t) to size_t for byteCount_ can truncate on 32-bit; consider checking the range before assignment. (Related to the cast above.)

🤖 React with 👍 or 👎 to let us know if the comment was useful.

Copy link
Copy Markdown
Owner Author

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.

available_ = 0;
}

Expand Down
7 changes: 6 additions & 1 deletion lang/c++/impl/parsing/Symbol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::is_same_v requires <type_traits>, but this TU doesn’t include it; consider adding the header to avoid relying on transitive includes and potential build failures.

🤖 React with 👍 or 👎 to let us know if the comment was useful.

Copy link
Copy Markdown
Owner Author

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:It seems <type_traits> is included transitively by some other header file but it is always better to be explicit !

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));
Expand Down
Loading