Skip to content

MISRA rule 7.2 Require 'u' prefix when using large unsigned integer constants#2881

Merged
danmar merged 3 commits into
cppcheck-opensource:mainfrom
larseven:dev
Nov 5, 2020
Merged

MISRA rule 7.2 Require 'u' prefix when using large unsigned integer constants#2881
danmar merged 3 commits into
cppcheck-opensource:mainfrom
larseven:dev

Conversation

@larseven

@larseven larseven commented Nov 4, 2020

Copy link
Copy Markdown
Contributor

MISRA rule 7.2 Require 'u' prefix when using large unsigned integer constants

@danmar danmar left a comment

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.

If CI will be happy I feel this can be merged.

@larseven

larseven commented Nov 4, 2020

Copy link
Copy Markdown
Contributor Author

I see the failing test (Expected but not seen: 242:7.2) and will fix it.

@larseven

larseven commented Nov 5, 2020

Copy link
Copy Markdown
Contributor Author

All tests are passing now so should be ready for merge.

Comment thread addons/misra.py Outdated
if value and value.isNumber:
if variable and variable.valueType and variable.valueType.sign == 'unsigned':
if variable.valueType.type in ['char', 'short', 'int', 'long', 'long long']:
constantValue = parseUnsignedNumber(value.str, 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.

Instead of this parsing.. I would prefer that you use Valueflow::Value instead.

In core Cppcheck the Token class has a few utility methods: Token::hasKnownValue() , Token::hasKnownIntValue() and Token::getKnownIntValue() .. I would like that the Token class in cppcheckdata.py also had such methods and then I would like that you used these instead here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, will look into it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the advice. I am now reading values using the value flow and I could remove my custom integer parser function. Should be available in my latest commit.

@danmar danmar merged commit c1212f8 into cppcheck-opensource:main Nov 5, 2020
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