Repository navigation
Fix false positives for std::byte pointer scaling - #22933
Merged
Merged
Conversation
Reproduce #22929 with int-pointer arithmetic from std::byte storage using C-style casts and reinterpret_cast. Record the current false positives alongside the existing char-pointer coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jketema
force-pushed
the
copilot/issue-22929-byte-pointer-scaling
branch
from
October 29, 2026 11:10
a77d53e to
73542ac
Compare
Treat std::byte source pointers like char and void buffers when checking pointer scaling, avoiding false positives for intentional typed indexing. Match only the standard byte enum and update both cast-style tests to expect no alerts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a minor analysis note for the reduced false positives in suspicious pointer scaling when indexing std::byte buffers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jketema
marked this pull request as ready for review
October 29, 2026 11:34
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified, and the narrowly scoped change includes targeted regression coverage for the std::byte pointer-casting cases.
No open issues 🎉
What changed in this PR
Updates cpp/suspicious-pointer-scaling to avoid false positives when intentional typed indexing starts from a std::byte* buffer.
Changes:
- Exempts source pointers based on the qualified
std::byteenum. - Adds regression coverage for C-style casts and
reinterpret_cast. - Documents the analysis improvement in a change note.
| File | Description |
|---|---|
cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/IncorrectPointerScaling/test.cpp |
Adds coverage for conversions from std::byte* using both cast forms. |
cpp/ql/src/Security/CWE/CWE-468/IncorrectPointerScaling.ql |
Exempts qualified std::byte source pointers from suspicious pointer-scaling results. |
cpp/ql/src/change-notes/2026-10-29-suspicious-pointer-scaling-byte.md |
Documents the false-positive reduction. |
Review effort: Lite (auto)
Contributor
Author
|
OpenTTD alerts that have disappeared from DCA indeed used |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
std::byte*source pointers fromcpp/suspicious-pointer-scaling, avoiding false positives for intentional typed indexing into byte buffers.reinterpret_cast, and document the analysis change.The exemption matches the standard
std::byteenum by qualified name. This is an enum by definition of the spec.std::byteshould be treated similar tochar, so should exempted here.Fixes #22929