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. |
|
I don't have Trac access, so could you create the ticket for this one? Once there's a number I'll update the title to "Fix #NNNN (...)" like the others. For the ticket: with A range that does fit, e.g. |
|
I have created https://trac.cppcheck.net/ticket/15181 |
|
ping? there is a small formatting thing. and resolve the merge conflict.. |
60ba520 to
5256aa3
Compare
|
Sorry for the delay. Rebased onto main (the conflict was just the include list, since main dropped |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. When the +N range is too large for an int, parseRange now catches std::out_of_range and returns 0, so the comment is treated like any other invalid range. When the range fits in an int but line + N would overflow, lineEnd is capped at INT_MAX before the addition happens. Block matching only compares line numbers against lineEnd (lib/suppressions.cpp:482 and :732), so capping it at INT_MAX does no harm. The new tests cover both cases.
Earlier comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | PR should have a trac ticket and the title should reference it | @dmcppcheck | general | ✅ Fixed |
| 2 | Small formatting fix needed and merge conflict to resolve | @danmar | general | ✅ Fixed |
Testing
- Built
cppcheckandtestrunnerin/work/pr; the build succeeded. ./testrunner TestSuppressionspassed with 0 failures.- I ran two inputs through the PR's cppcheck with
--inline-suppr --addon=misra. Both exited with code 0 and printed nothing, so there was no crash or abort:printf 'int x;\n/* polyspace +99999999999 MISRA2012:8.4 */\nint y;\n' > b.c, the case from the description.- The same file with
+2147483647.
- I couldn't run the premium options: this build rejects
--premium=misra-c-2012with "unrecognized command line option". - I didn't build
base/and didn't run a sanitizer build, so I haven't seen the crash or the UBSan overflow on main for myself.
Automated review of 5256aa3 by Claude. The pull request was built and tested locally.
| pos = endpos; | ||
| return ret; | ||
| } catch (const std::invalid_argument &) {} | ||
| } catch (const std::invalid_argument &) {} catch (const std::out_of_range &) {} |
There was a problem hiding this comment.
I prefer catch statements on separate lines.
There was a problem hiding this comment.
Done, each catch is on its own line now.
There was a problem hiding this comment.
Splitting them tripped the format job: nl_collapse_empty_body folds the empty bodies back into } catch (...) {} catch (...) {}, so uncrustify kept undoing it. I put a short comment in each body, which keeps them on separate lines and leaves ./runformat with nothing to change (checked against uncrustify 0.80.1). Pushed as 047e277.
The build_cygwin failure looks unrelated, the cygwin install action itself fails before anything is compiled.
| suppr.type = SuppressionList::Type::block; | ||
| suppr.lineBegin = line; | ||
| suppr.lineEnd = line + rangeValue; | ||
| suppr.lineEnd = (rangeValue > std::numeric_limits<int>::max() - line) ? std::numeric_limits<int>::max() : (line + rangeValue); |
There was a problem hiding this comment.
I don't remember.. is it guaranteed that line is positive?
I assume it should be but would it make sense to check that it is or is that just redundant?
There was a problem hiding this comment.
Not guaranteed, so the check isn't redundant. simplecpp only warns on #line 0 or #line values above 2147483647 and keeps the value, and Location::line is unsigned, so #line 4294967295 reaches parse() as -1. With the previous expression INT_MAX - line then overflowed itself (UBSan: 2147483647 - -1). Rather than special-casing the sign I now do the addition in long long and clamp to INT_MAX, which is safe for any int line, and added a polyspaceRange case with line -1.
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. parseRange now catches std::out_of_range and returns 0, so a range that is too large is ignored like the existing +A case. lineEnd is computed as long long and capped at INT_MAX, which is safe for any int value of line, including the negative values that #line 4294967295 produces. The new unit tests cover the out-of-range value, +INT_MAX and line == -1.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | PR needs a trac ticket and the title should reference it | @dmcppcheck | general | ✅ Fixed |
| 2 | Small formatting fix and merge conflict to resolve | @danmar | general | ✅ Fixed |
| 3 | Put catch statements on separate lines | @danmar | lib/suppressions.cpp:925 |
✅ Fixed |
| 4 | Is line guaranteed positive? INT_MAX - line could overflow | @danmar | lib/suppressions.cpp:889 |
✅ Fixed |
Testing
- Built
cppcheckandtestrunnerin/work/prwithmake -j8; the build succeeded. ./testrunner TestSuppressionspassed all 71 tests with 0 failures.- Ran
cppcheck --inline-suppr --addon=misra -qfrom the PR on these scratch files. All of them exited with code 0 and printed nothing, so nothing crashed:/* polyspace +99999999999 MISRA2012:8.4 */on line 2/* polyspace +2147483647 MISRA2012:8.4 */on line 2#line 4294967295followed by/* polyspace +5 MISRA2012:8.4 */+-99999999999, and a+Nvalue with 29 digits
- I did not build
base/or a sanitizer build, so I have not seen the crash on main or confirmed that UBSan is now quiet.
Automated review of 047e277 by Claude. The pull request was built and tested locally.
|
Test results for commit 047e277 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8956/ 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. |
| suppr.type = SuppressionList::Type::block; | ||
| suppr.lineBegin = line; | ||
| suppr.lineEnd = line + rangeValue; | ||
| suppr.lineEnd = static_cast<int>(std::min<long long>(std::numeric_limits<int>::max(), static_cast<long long>(line) + rangeValue)); |
There was a problem hiding this comment.
the casts hurt readability. and we could limit the addition operand instead..
| suppr.lineEnd = static_cast<int>(std::min<long long>(std::numeric_limits<int>::max(), static_cast<long long>(line) + rangeValue)); | |
| suppr.lineEnd = line + std::min(rangeValue, std::numeric_limits<int>::max() - line); |
we know that line is not negative here right? If line could be negative it's better to limit the lhs in the addition instead .. + rangeValue.
There was a problem hiding this comment.
No, line isn't guaranteed non-negative, so I took the second option and limited the lhs:
suppr.lineEnd = std::min(line, std::numeric_limits<int>::max() - rangeValue) + rangeValue;simplecpp only warns about #line 4294967295 and keeps the value, and Location::line is unsigned, so that reaches parse() as -1. std::numeric_limits<int>::max() - line would then overflow by itself, which is why I had the long long version. Limiting the lhs avoids that: rangeValue is > 0 in this branch, so max() - rangeValue can't overflow and the sum stays <= INT_MAX for any int line. Casts are gone.
Pushed as e3249e4. TestSuppressions passes (71 tests) and so does the full testrunner (5393 tests, 0 failures); the polyspaceRange cases for +2147483647 and line -1 still cover both ends.
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. parseRange now catches std::out_of_range, and a +N that doesn't fit in an int is handled like +A. lineEnd is computed as std::min(line, INT_MAX - rangeValue) + rangeValue. That expression cannot overflow, because rangeValue > 0 in this branch, and it handles negative line values too. The earlier review points (trac ticket, formatting, catch clauses on separate lines, possibly negative line, removing the casts) are all addressed in the current code.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | PR needs a trac ticket and the title should reference it | @dmcppcheck | general | ✅ Fixed |
| 2 | Small formatting fix and merge conflict to resolve | @danmar | general | ✅ Fixed |
| 3 | Put catch statements on separate lines | @danmar | lib/suppressions.cpp:925 |
✅ Fixed |
| 4 | Is line guaranteed positive? Overflow if negative | @danmar | lib/suppressions.cpp:889 |
✅ Fixed |
| 5 | Casts hurt readability; limit the addition operand instead | @danmar | lib/suppressions.cpp:889 |
✅ Fixed |
Testing
- Build:
make -j8 cppcheck testrunnerin/work/prsucceeded. - Unit tests:
./testrunner TestSuppressionsran 71 tests with 0 failures. - End-to-end runs: I ran
cppcheck --inline-suppr --addon=misra -qfrom the PR on files containing/* polyspace +N MISRA2012:8.4 */on line 2, with N = 99999999999, 2147483647, 2147483646 and 1. All of them exited with code 0, with no abort. - Overflow check: I compiled the new
lineEndexpression on its own with-fsanitize=undefined -fno-sanitize-recover. I triedline∈ {INT_MIN, -1, 0, 1, 2, INT_MAX-1, INT_MAX} andrangeValue∈ {1, 2, 5, INT_MAX}. UBSan reported nothing, and the results are correct and capped at INT_MAX. - Not done: I did not build
base/and did not do a full sanitizer build of cppcheck.
Automated review of e3249e4 by Claude. The pull request was built and tested locally.
|
Test results for commit e3249e4 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8956/ 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. |
polyspace::Parser::parseRange reads the +N range of a Polyspace comment with std::stoi and only catches std::invalid_argument, so a source file containing
/* polyspace +99999999999 MISRA2012:8.4 */throws std::out_of_range past CppCheck::checkFile and aborts cppcheck when it runs with --inline-suppr and the misra addon or a premium MISRA/CERT option. A range that does fit, such as +2147483647 on line 2, instead overflowsline + rangeValuein Parser::parse (UBSan: signed integer overflow) and leaves a negative lineEnd. An out-of-range number is now treated like any other invalid range, and lineEnd is clamped to INT_MAX instead of wrapping, so valid ranges are unchanged. The new asserts in polyspaceParseRange and polyspaceRange fail on main, and the full testrunner passes in an ASan/UBSan build. Trac ticket: https://trac.cppcheck.net/ticket/15181