From 5256aa31156e43aa00e2a36f4a50f2af98212ed1 Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Thu, 22 Oct 2026 19:27:09 +0530 Subject: [PATCH 1/4] fix polyspace +N range overflow in inline suppressions --- lib/suppressions.cpp | 5 +++-- test/testsuppressions.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 0089510c86f..0de87f2493f 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 = (rangeValue > std::numeric_limits::max() - line) ? std::numeric_limits::max() : (line + rangeValue); } else if (polyspaceKind == polyspace::CommentKind::Regular) suppr.type = SuppressionList::Type::unique; @@ -921,7 +922,7 @@ 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..b5d69e9c84b 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,12 @@ 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() } } + ); } void polyspaceBlock() const { From aab3e792ccb4103cbe90fa6ca9f5c17cdbaea28e Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Sat, 14 Nov 2026 00:05:58 +0530 Subject: [PATCH 2/4] polyspace: compute lineEnd in long long, split catch clauses --- lib/suppressions.cpp | 6 ++++-- test/testsuppressions.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 0de87f2493f..c9c7ce7ac55 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -886,7 +886,7 @@ std::list polyspace::Parser::parse(const std::stri if (rangeValue > 0) { suppr.type = SuppressionList::Type::block; suppr.lineBegin = line; - suppr.lineEnd = (rangeValue > std::numeric_limits::max() - line) ? std::numeric_limits::max() : (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; @@ -922,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::out_of_range &) {} + } catch (const std::invalid_argument &) { + } catch (const std::out_of_range &) { + } return 0; } diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index b5d69e9c84b..1a28ccd45ab 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -2407,6 +2407,12 @@ class TestSuppressions : public TestFixture { { "/* 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 { From 047e2774de989124720b286dff71f4cdc3c81150 Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Thu, 26 Nov 2026 13:13:48 +0530 Subject: [PATCH 3/4] polyspace: keep the two catch clauses on separate lines for uncrustify --- lib/suppressions.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index c9c7ce7ac55..8d1dcd1b572 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -923,7 +923,9 @@ int polyspace::Parser::parseRange(const std::string& comment, std::string::size_ pos = endpos; return ret; } catch (const std::invalid_argument &) { + // not a number } catch (const std::out_of_range &) { + // does not fit in an int } return 0; } From e3249e4168471c3f8dc1868d99e9a4e8f8b09559 Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Mon, 30 Nov 2026 00:24:13 +0530 Subject: [PATCH 4/4] polyspace: limit the addition operand instead of casting to long long --- lib/suppressions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 8d1dcd1b572..9a4e32c70fd 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -886,7 +886,8 @@ std::list polyspace::Parser::parse(const std::stri if (rangeValue > 0) { suppr.type = SuppressionList::Type::block; suppr.lineBegin = line; - suppr.lineEnd = static_cast(std::min(std::numeric_limits::max(), static_cast(line) + rangeValue)); + // line can be negative, so limit the lhs; rangeValue > 0 keeps the sum <= INT_MAX + suppr.lineEnd = std::min(line, std::numeric_limits::max() - rangeValue) + rangeValue; } else if (polyspaceKind == polyspace::CommentKind::Regular) suppr.type = SuppressionList::Type::unique;