Wrong type parsing for library functions (from /cfg)#967
Merged
Conversation
wrong type detection
Collaborator
|
thanks! Spontaneously I am skeptic about moving this functionality into tokenlist. But I need to take a closer look. |
Collaborator
|
After looking into this I think your solution is the right one. thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.