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.
| 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.
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. There is no Trac ticket for this yet; I can update the title once one exists.