Skip to content

fix crash while checking misra_9 when initializing a union with {{0,0}}#5250

Merged
danmar merged 2 commits intocppcheck-opensource:mainfrom
Sevenstax:master
Aug 31, 2023
Merged

fix crash while checking misra_9 when initializing a union with {{0,0}}#5250
danmar merged 2 commits intocppcheck-opensource:mainfrom
Sevenstax:master

Conversation

@ev1313
Copy link
Copy Markdown
Contributor

@ev1313 ev1313 commented Jul 18, 2023

This fixes a crash with following error:

Traceback (most recent call last):
  File "/usr/local/share/Cppcheck/addons/runaddon.py", line 8, in <module>
    runpy.run_path(addon, run_name='__main__')
  File "<frozen runpy>", line 291, in run_path
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/share/Cppcheck/addons/misra.py", line 4737, in <module>
    main()
  File "/usr/local/share/Cppcheck/addons/misra.py", line 4679, in main
    checker.parseDump(item)
  File "/usr/local/share/Cppcheck/addons/misra.py", line 4335, in parseDump
    self.executeCheck(902, self.misra_9_2, cfg)
  File "/usr/local/share/Cppcheck/addons/misra.py", line 4246, in executeCheck
    check_function(*args)
  File "/usr/local/share/Cppcheck/addons/misra.py", line 2104, in misra_9_2
    misra_9.misra_9_x(self, data, 902)
  File "/usr/local/share/Cppcheck/addons/misra_9.py", line 414, in misra_9_x
    parser.parseInitializer(ed, eq.astOperand2)
  File "/usr/local/share/Cppcheck/addons/misra_9.py", line 320, in parseInitializer
    child = self.root.getChildByValueElement(self.ed)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'getChildByValueElement'

A minimal example and testcase is added.
The extra check for nextChild seems to fix it, however i did not read the whole codebase, so maybe this creates other issues.

Comment thread addons/test/test-misra.py Outdated
Comment thread addons/misra_9.py Outdated
@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Aug 7, 2023

Thanks a lot for this fix! I am very sorry for the slow reply. I just have a few small nits hope you want to fix it.

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.

If my small nits are fixed I believe it's fine to merge this.

@ev1313
Copy link
Copy Markdown
Contributor Author

ev1313 commented Aug 30, 2023

I updated accordingly

@danmar danmar merged commit b70e1df into cppcheck-opensource:main Aug 31, 2023
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