Skip to content

Wrong type parsing for library functions (from /cfg)#967

Merged
danmar merged 1 commit into
cppcheck-opensource:masterfrom
aeryomenko:master
Oct 3, 2017
Merged

Wrong type parsing for library functions (from /cfg)#967
danmar merged 1 commit into
cppcheck-opensource:masterfrom
aeryomenko:master

Conversation

@aeryomenko
Copy link
Copy Markdown
Contributor

I have observed a false positive while analyzing my project. An example of code caused cppcheck warnings:
void f() { const char *s = "0"; printf("%ld%lld", atol(s), atoll(s)); }
And warnings themselves:
[test.cpp:3]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'signed int'.
[test.cpp:3]: (warning) %lld in format string (no. 2) requires 'long long' but the argument type is 'signed int'.

Configuration for functions in std.cfg were ok: return value type for atol - long int, for atoll - long long int. Further reading of source code led to the conclusion that cppcheck uses only last keyword in the configured string - int, because return value type was not rolled up as it is done in the tokenizer for the analized file.
In my patch I suggest to move method Tokenizer.simplifyStdType to the TokenList class and to use it just before the parsing of declararion for standard library function.
I have added example of code written above as IO unit test. I am not sure that is a good place for it, probably test should be rewritten in some other way.

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Oct 3, 2017

thanks! Spontaneously I am skeptic about moving this functionality into tokenlist. But I need to take a closer look.

@danmar danmar merged commit 22483ba into cppcheck-opensource:master Oct 3, 2017
@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Oct 3, 2017

After looking into this I think your solution is the right one. thanks!

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