diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 0089510c86f..c9c7ce7ac55 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -32,6 +32,7 @@ #include // std::isdigit, std::isalnum, etc #include #include +#include #include #include #include @@ -885,7 +886,7 @@ std::list polyspace::Parser::parse(const std::stri if (rangeValue > 0) { suppr.type = SuppressionList::Type::block; suppr.lineBegin = line; - suppr.lineEnd = line + rangeValue; + suppr.lineEnd = static_cast(std::min(std::numeric_limits::max(), static_cast(line) + rangeValue)); } else if (polyspaceKind == polyspace::CommentKind::Regular) suppr.type = SuppressionList::Type::unique; @@ -921,7 +922,9 @@ int polyspace::Parser::parseRange(const std::string& comment, std::string::size_ int ret = std::stoi(range); pos = endpos; return ret; - } catch (const std::invalid_argument &) {} + } catch (const std::invalid_argument &) { + } catch (const std::out_of_range &) { + } return 0; } diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index fbdcb6307e5..1a28ccd45ab 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -2206,6 +2207,10 @@ class TestSuppressions : public TestFixture { pos = 0; ASSERT_EQUALS(0, polyspace::Parser::parseRange(" +A ",pos)); ASSERT_EQUALS(1U, pos); + + pos = 0; + ASSERT_EQUALS(0, polyspace::Parser::parseRange(" +99999999999 ",pos)); + ASSERT_EQUALS(1U, pos); } void polyspaceParseIds() const { @@ -2396,6 +2401,18 @@ class TestSuppressions : public TestFixture { { "/* polyspace +3 MISRA2012 : 2.7 */", 1 }, { { "premium-misra-c-2012-2.7", 1, "", SuppressionList::Type::block, 1, 4 } } ); + + testPolyspaceSuppression( + "", "--misra-c-2012", + { "/* polyspace +2147483647 MISRA2012 : 2.7 */", 2 }, + { { "premium-misra-c-2012-2.7", 2, "", SuppressionList::Type::block, 2, std::numeric_limits::max() } } + ); + + testPolyspaceSuppression( + "", "--misra-c-2012", + { "/* polyspace +5 MISRA2012 : 2.7 */", -1 }, + { { "premium-misra-c-2012-2.7", -1, "", SuppressionList::Type::block, -1, 4 } } + ); } void polyspaceBlock() const {