Skip to content

fixed #13982 - cppcheck.cpp: do not crash if mExecuteCommand is empty #7647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 15, 2025

Conversation

firewave
Copy link
Collaborator

@firewave firewave commented Jul 6, 2025

No description provided.

@firewave firewave changed the title refs #13982 - cppcheck.cpp: do not crash if mExecuteCommand is empty fixed #13982 - cppcheck.cpp: do not crash if mExecuteCommand is empty Jul 6, 2025
@firewave
Copy link
Collaborator Author

firewave commented Jul 6, 2025

This only fixes the crash when running an scratchpad analysis with a loaded projects including addons. It will now show an error instead.

The execute function is not available in that context and it requires some refactoring. But I think that is something to look into in the context of https://trac.cppcheck.net/ticket/13976.

@firewave

This comment was marked as resolved.

@firewave firewave marked this pull request as draft July 6, 2025 22:42
@firewave firewave marked this pull request as ready for review July 6, 2025 23:18
@firewave firewave marked this pull request as draft July 7, 2025 09:35
@firewave firewave force-pushed the scratch-addon branch 4 times, most recently from 988764d to e6a6e24 Compare July 7, 2025 11:00
@firewave
Copy link
Collaborator Author

firewave commented Jul 7, 2025

I moved the checks from the executor tests as the code being tested was not specific to those classes and actually lives in CppCheck.

@firewave firewave marked this pull request as ready for review July 7, 2025 11:50
@@ -686,6 +689,11 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file, int fileIndex)
mErrorLogger.reportOut(exe + " " + args2, Color::Reset);
}

if (!mExecuteCommand) {
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no command callback provided)" << std::endl;
Copy link
Owner

Choose a reason for hiding this comment

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

why isn't this reported to the errorlogger. GUI does not capture stderr. And plugins will probably not write this. So the user will have no clue why it does not work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because that was never properly implemented for this. It's the same in another cases and there's TODOs in the code. Will check if we have tickets about this.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand what I am missing. What is stopping you from calling mErrorLogger.reportError here instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't understand what I am missing. What is stopping you from calling mErrorLogger.reportError here instead?

It just was never implemented that way back when this functionality was introduced. That is outside of the scope of this PR.

Copy link
Owner

Choose a reason for hiding this comment

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

If we write this code instead:

        const std::list<ErrorMessage::FileLocation> callstack{
            {file.spath(), -1, 0}
        };
        const ErrorMessage msg(callstack, nullptr, Severity::error, "internalError", "Failed to execute clang, mExecuteCommand is null", Certainty::normal);
        mErrorLogger.reportErr(msg);

It still compiles. I don't ask that you change other std::cerr/std::cout statements throughout the code, those should be fixed but I agree that is out of scope.

Copy link
Owner

Choose a reason for hiding this comment

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

maybe a throw InternalError is easier.. your choice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will file tickets and address this in a follow-up.

@firewave
Copy link
Collaborator Author

[![Quality Gate Failed]

Great - this is back. Now any build will show up as failed after it has been merged...

@@ -432,6 +432,9 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
const std::string &premiumArgs,
const CppCheck::ExecuteCmdFn &executeCommand)
{
if (!executeCommand)
throw InternalError(nullptr, "Failed to execute addon - no command callback provided");
Copy link
Owner

Choose a reason for hiding this comment

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

how about writing it more detailed..
Cannot execute addon, function pointer 'executeCommand' is null

@@ -686,6 +689,11 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file, int fileIndex)
mErrorLogger.reportOut(exe + " " + args2, Color::Reset);
}

if (!mExecuteCommand) {
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no command callback provided)" << std::endl;
Copy link
Owner

Choose a reason for hiding this comment

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

If we write this code instead:

        const std::list<ErrorMessage::FileLocation> callstack{
            {file.spath(), -1, 0}
        };
        const ErrorMessage msg(callstack, nullptr, Severity::error, "internalError", "Failed to execute clang, mExecuteCommand is null", Certainty::normal);
        mErrorLogger.reportErr(msg);

It still compiles. I don't ask that you change other std::cerr/std::cout statements throughout the code, those should be fixed but I agree that is out of scope.

@@ -686,6 +689,11 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file, int fileIndex)
mErrorLogger.reportOut(exe + " " + args2, Color::Reset);
}

if (!mExecuteCommand) {
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no command callback provided)" << std::endl;
Copy link
Owner

Choose a reason for hiding this comment

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

maybe a throw InternalError is easier.. your choice.

@danmar
Copy link
Owner

danmar commented Jul 15, 2025

Great - this is back. Now any build will show up as failed after it has been merged

we have several successful builds.

if the configuration will need adjustments I am open to suggestions. I like to get more warnings but my feeling is that sonar is a lot more noisy. but I haven't seen any failed builds because of sonarcloud since yesterday at least.

@firewave
Copy link
Collaborator Author

firewave commented Aug 4, 2025

This should have been in the release... Will rebase later so it can be merged. Unless thee is still something to do.

Copy link

sonarqubecloud bot commented Aug 4, 2025

@firewave firewave merged commit 107e226 into danmar:main Aug 15, 2025
63 checks passed
@firewave firewave deleted the scratch-addon branch August 15, 2025 08:16
Comment on lines +1965 to +1969
if (!mExecuteCommand) {
std::cerr << "Failed to execute '" << exe << "' (no command callback provided)" << std::endl;
return;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reporting a proper error is already tracked in https://trac.cppcheck.net/ticket/13827.

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.

2 participants