Skip to content

Fix #901 Improve out-of-bounds check to detect error with sprintf()#8473

Open
chrchr-github wants to merge 1 commit intocppcheck-opensource:mainfrom
chrchr-github:chr_901
Open

Fix #901 Improve out-of-bounds check to detect error with sprintf()#8473
chrchr-github wants to merge 1 commit intocppcheck-opensource:mainfrom
chrchr-github:chr_901

Conversation

@chrchr-github
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/checkbufferoverrun.cpp Dismissed
@sonarqubecloud
Copy link
Copy Markdown

if (inputArgNr < parameters.size() && parameters[inputArgNr]->tokType() == Token::eString)
parameterLength = Token::getStrLength(parameters[inputArgNr]);
if (inputArgNr < parameters.size())
parameterLength = ValueFlow::valueFlowGetStrLength(parameters[inputArgNr], settings);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Looks like a false positive.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree. And it might be fixed in latest cppcheck premium I fail to reproduce..

@chrchr-github chrchr-github marked this pull request as ready for review April 21, 2026 20:08
"}", settings);
ASSERT_EQUALS("", errout_str());

check("void f() {\n" // #901
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are there some related test to ensure there is not false positives. I.e. if a size is 2 instead.

if (inputArgNr < parameters.size() && parameters[inputArgNr]->tokType() == Token::eString)
parameterLength = Token::getStrLength(parameters[inputArgNr]);
if (inputArgNr < parameters.size())
parameterLength = ValueFlow::valueFlowGetStrLength(parameters[inputArgNr], settings);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree. And it might be fixed in latest cppcheck premium I fail to reproduce..

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.

4 participants