Repository navigation
Conversation
|
There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated. |
|
hey can anyone create trac ticket for this pr, thanks. |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
No new problems found. The two guards stop the out-of-range shifts and do not change results for widths of 1–63 bits; with value_size == 8 the old code already left the value unchanged, so only sizes of 0 and above 8 (and bit == 0 in castValue) behave differently. The mixed-sign comparison of unknown-size types such as int_fast8_t == uint_fast8_t is no longer reported as always true. The trac ticket that C1 asked for does not exist yet.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | PR needs a trac ticket and the title should be updated | @dmcppcheck | general |
@Nussu06, please fix, resolve or reply to the open and new comments: #1.
Testing
- Builds:
make -j8 cppcheck testrunnerbuilt cleanly inpr/, andmake -j8 cppcheckbuilt cleanly inbase/. - Changed suites:
./testrunner TestValueFlow TestCondition TestOther TestTyperan 433 tests and none failed. - Full testrunner:
./testrunner -qran 5425 tests and none failed. - Comparison with base: I ran both binaries on a scratch file with
cppcheck -q --enable=all --check-level=exhaustive a.cpp:int_fast8_t a = 0; uint_fast8_t b = 10; if (a == b): base reportsCondition 'a==b' is always true, a false positive; the PR reportsalways false, which is correct.int_fast16_t a = -1; uint_fast16_t b = 5; if (a == b): base reportsalways true, which is wrong; the PR reportsalways false.- These cases came out the same on both binaries, and correctly:
unsigned char255 wraps to 0 after++.signed char127 becomes -128 after++.long long-1 compared withunsigned long long0xffff…ffff isalways false.int_fast8_t-1 compared withunsigned int0xffffffff isalways true.
++on a 12-byte struct withoperator++gave no warnings and did not crash.
- Not done: I did not run a UBSan build.
Automated review of 3b275f0 by Claude. The pull request was built and tested locally.
|
Test results for commit 3b275f0 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9073/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
ValueFlow::castValue and ValueFlow::truncateIntValue in lib/vf_common.cpp shift by a bit width taken from ValueType::getSizeOf, which is 0 for integer types of unknown size and above 64 for records and containers, so a prefix ++ or -- on a struct or container variable shifts by a count far outside 64 bits (UBSan at vf_common.cpp:104, and for a 12 byte struct the value is truncated to 32 bits), and a mixed-sign comparison of two unknown-size types such as int_fast8_t and uint_fast8_t shifts by -1 and zeroes the value, which reports
int_fast8_t a = 0; uint_fast8_t b = 10; if (a == b)as always true. Both helpers now return the value unchanged when the width is 0 or 64 bits and above, matching the sz < 8 guard the other truncateIntValue callers already have; widths of 1 to 63 bits are handled exactly as before. The new asserts in TestValueFlow::valueFlowIncDec and valueFlowUnsigned fail on main and pass with the change, the full testrunner passes in a normal build and under -fsanitize=undefined, and the touched files are unchanged by uncrustify. I do not have Trac access, so could one of you create a ticket for this? I will update the title to Fix #NNNNN (...) once it exists.