-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix type mismatch of line and column number and add extra information in misra-reports #5407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1c6f79f
608281e
7ecf24b
b8690f5
9a4912b
ceb8905
9c4aec1
2f5b55d
05df446
9e0c2db
097672b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,8 +119,8 @@ def __init__(self, element): | |
| self.name = element.get('name') | ||
| _load_location(self, element) | ||
| self.usefile = element.get('usefile') | ||
| self.useline = element.get('useline') | ||
| self.usecolumn = element.get('usecolumn') | ||
| self.useline = int(element.get('useline')) | ||
| self.usecolumn = int(element.get('usecolumn')) | ||
| self.isKnownValue = element.get('is-known-value', 'false') == 'true' | ||
|
|
||
| def __repr__(self): | ||
|
|
@@ -1612,7 +1612,7 @@ def is_suppressed(location, message, errorId): | |
| return True | ||
| return False | ||
|
|
||
| def reportError(location, severity, message, addon, errorId, extra=''): | ||
| def reportError(location, severity, message, addon, errorId, misra_severity='', extra=''): | ||
| if '--cli' in sys.argv: | ||
| msg = { 'file': location.file, | ||
| 'linenr': location.linenr, | ||
|
|
@@ -1621,12 +1621,14 @@ def reportError(location, severity, message, addon, errorId, extra=''): | |
| 'message': message, | ||
| 'addon': addon, | ||
| 'errorId': errorId, | ||
| 'extra': extra} | ||
| 'extra': misra_severity} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't we just use the extra. If "extra" has some text (reported from misc.py or any other addon) then why isn't that used in the output?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not use extra, because today in misra.py misra_severity is stored in the extra field.
I use my own reportError function, that does write a XML-file, that is close to what cppcheck creates today. And I did not want to change the reportError function provided in cppcheckdata.py significantly to avoid any problems. So since misra.py writes severity information twice (cppcheck_severity and misra_severity) I could remove the misra_severity from misra.py, and replace that with extra or verbose information. But then I might break something when the misra checks are called through cppcheck, because then the --cli option seems to get added automatically. And the misra_severity could be used somewhere. I would like to get the extra information inside, so if you can tell me how you would like me to update the code. I will try to prepare the update.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I do not see that here in this PR.. do you have some special function locally that writes different xml file?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using cppcheck since 1.80, and misra.py evolved a lot. I customized some checks, to not show certain issues, added custom checks, .. and to avoid merging misra.py with mine, I added a wrapper around the misra.py, and it has a XML-write feature, but I can't recall why I did that.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok thanks |
||
| sys.stdout.write(json.dumps(msg) + '\n') | ||
| else: | ||
| if is_suppressed(location, message, '%s-%s' % (addon, errorId)): | ||
| return | ||
| loc = '[%s:%i]' % (location.file, location.linenr) | ||
| if len(misra_severity) > 0: | ||
| message += ' (' + severity + ')' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code is strange. is the intention to append the misra severity to the message? |
||
| if len(extra) > 0: | ||
| message += ' (' + extra + ')' | ||
| sys.stderr.write('%s (%s) %s [%s-%s]\n' % (loc, severity, message, addon, errorId)) | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spontanously it does not feel very good to add a "misra_severity" here. This is the generic function it's not related to misra. We have other addons also and I don't want to add various special parameters for those.
So well one approach could be to rename the parameters somehow to have generic parameters that works for all addons..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not technically add the misra_severity, I just renamed the parameter, to the argument name used in misra.py, and then I re-used the extra parameter, for the extra information I wanted to add, since it seemed like a good name for additional error information.
https://github.com/danmar/cppcheck/blob/a87e9e104239785058e91811ea1dbf5bdc44e919/addons/misra.py#L4132
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is not a good name for all the other addons.
If I report an error in the misc.py addon and then I want to provide some extra information to the error message then I don't feel that we should use
misra_severity.. and I don't want to add more parameters like misc_severity or misc_hint.. I want to reuse the same options.I want a generic argument name that will make sense in other addons also.