Skip to content

Conversation

@ludviggunne
Copy link
Collaborator

No description provided.

@firewave
Copy link
Collaborator

Should this be behind a flag? Always parsing for something very niche (and premium only?) seems undesired.

@ludviggunne
Copy link
Collaborator Author

Should this be behind a flag? Always parsing for something very niche (and premium only?) seems undesired.

I think that would be good.

@ludviggunne ludviggunne force-pushed the 14367 branch 2 times, most recently from 565b38a to d27f25b Compare January 11, 2026 18:19
@firewave
Copy link
Collaborator

Should this be behind a flag? Always parsing for something very niche (and premium only?) seems undesired.

I think that would be good.

Since it is specific to certain MISRA rules it should only be active if those rules are active.

@ludviggunne ludviggunne force-pushed the 14367 branch 2 times, most recently from 73a5159 to da0456b Compare January 11, 2026 18:41
@danmar
Copy link
Owner

danmar commented Jan 12, 2026

Should this be behind a flag? Always parsing for something very niche (and premium only?) seems undesired.

I agree it's niche use case. Especially for open source projects.

imho.. if --premium=misra-c-2012 --inline-suppr or --addon=misra.json --inline-suppr is used then I suggest that the polyspace comments are handled.

If misra checkers are not enabled then it's redundant to handle the polyspace comments.

@sonarqubecloud
Copy link

Comment on lines +332 to +336
if (s.isPolyspace) {
errorLogger.reportErr(::ErrorMessage(std::move(callStack), "", Severity::information, "Unmatched polyspace suppression: " + s.errorId, "unmatchedPolyspaceSuppression", Certainty::normal));
} else {
errorLogger.reportErr(::ErrorMessage(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", Certainty::normal));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. we can make sure that only the id is different;

Suggested change
if (s.isPolyspace) {
errorLogger.reportErr(::ErrorMessage(std::move(callStack), "", Severity::information, "Unmatched polyspace suppression: " + s.errorId, "unmatchedPolyspaceSuppression", Certainty::normal));
} else {
errorLogger.reportErr(::ErrorMessage(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", Certainty::normal));
}
const std::string unmatchSuppressionId = s.isPolyspace ? "unmatchedPolyspaceSuppression" : "unmatchedSuppression";
errorLogger.reportErr(::ErrorMessage(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, unmatchedSuppression, Certainty::normal));

return pos == args.size() - arg.size() || args[pos + arg.size()] == ' ';
};

if (settings.addons.count("misra") != 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is false if --addon=misra.json is used. I think it's more reliable to check if Settings::addonInfo contains an misra entry.


void polyspace::Parser::parse(const std::string &comment, int line, const std::string &filename)
{
mComment = comment;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (mFamilyMap.empty())
    return;

if (mComment.compare(0, 2, "/*") == 0 || mComment.compare(0, 2, "//") == 0)
mComment = mComment.substr(2);

std::string::size_type pos = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mComment can be empty now can't it?

return mPeeked;
}

if (mComment.compare(0, 2, "/*") == 0 || mComment.compare(0, 2, "//") == 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks suspicious. do you expect "//" inside a comment also? not just at the start.
should // inside a comment be silently skipped.

Settings settings;
settings.addons.emplace("misra");
polyspace::Parser parser(settings);
parser.parse("/* polyspace MISRA2012 : 2.7 */", 1, "file.c");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's unfortunate to duplicate so much code for each test. It makes it hard to see what you test.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which are the possible formats that you handle? I have seen this:

/* polyspace +1 MISRA-C3:20.1 [Justified:Low] "testing"*/

Is comments that contains +1, [Justified:Low], "..." handled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants