Skip to content

utils.h: reject unexpected preceding characters in strToInt()#8490

Merged
firewave merged 5 commits intocppcheck-opensource:mainfrom
firewave:test-stoi
Apr 26, 2026
Merged

utils.h: reject unexpected preceding characters in strToInt()#8490
firewave merged 5 commits intocppcheck-opensource:mainfrom
firewave:test-stoi

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/utils.h Fixed
Comment thread lib/utils.h Fixed
@firewave firewave marked this pull request as draft April 25, 2026 08:44
@firewave firewave marked this pull request as ready for review April 25, 2026 09:38
Comment thread lib/utils.h
*err = "needs to be positive";
return false;
}
if (str.front() != '+' && isdigit(str.front()) == 0) {
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 don't have good reasons but personally I would prefer !

Suggested change
if (str.front() != '+' && isdigit(str.front()) == 0) {
if (str.front() != '+' && !isdigit(str.front())) {

== 0 is a bit like misleading somehow..

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.

That was my original code but it produces a Cppcheck Premium warning because you check an integer result with !.

Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

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

I just have a little nit.

@firewave firewave merged commit 0294253 into cppcheck-opensource:main Apr 26, 2026
70 checks passed
@firewave firewave deleted the test-stoi branch April 26, 2026 08:28
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