Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <cstring>
#include <exception>
#include <functional> // std::bind, std::placeholders
#include <limits>
#include <sstream>
#include <stdexcept>
#include <utility>
Expand Down Expand Up @@ -850,7 +851,7 @@ std::list<SuppressionList::Suppression> 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<int>::max() - line) ? std::numeric_limits<int>::max() : (line + rangeValue);
}
else if (polyspaceKind == polyspace::CommentKind::Regular)
suppr.type = SuppressionList::Type::unique;
Expand Down Expand Up @@ -886,7 +887,8 @@ 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;
}

Expand Down
11 changes: 11 additions & 0 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <cstring>
#include <initializer_list>
#include <limits>
#include <list>
#include <map>
#include <memory>
Expand Down Expand Up @@ -2175,6 +2176,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 {
Expand Down Expand Up @@ -2365,6 +2370,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<int>::max() } }
);
}

void polyspaceBlock() const {
Expand Down
Loading