Commit Graph

20 Commits

Author SHA1 Message Date
Tim Blume b70e1df26c
fix crash while checking misra_9 when initializing a union with {{0,0}} (#5250)
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.

---------

Co-authored-by: Tim Blume <tbl@sevenstax-intern.de>
2023-08-31 09:38:03 +02:00
Oliver Stöneberg 5a322365a6
fixed `scriptcheck.yml` (#5268) 2023-08-01 13:06:12 +02:00
Daniel Marjamäki 9c5275f514
misra: fix 9.x checking when string literals are used to initialize char arrays (#5234) 2023-07-11 17:57:55 +02:00
Daniel Marjamäki 80c42fcaf3
misra: Fix crash in misra_9.py when struct type is unknown and there is string initialization (#5233) 2023-07-11 13:40:19 +02:00
Daniel Marjamäki a04990d4e3
misra 9.2: do not crash when checking. string literal is allowed to initialize array member. (#5232) 2023-07-10 22:50:24 +02:00
Daniel Marjamäki 2cd1f0f387
misra: Fix crash in misra_9x when there is unknown constant used as array size (#5229) 2023-07-10 12:25:28 +02:00
Daniel Marjamäki 276aace331
Misra: Fix crash (#5228) 2023-07-09 19:17:59 +02:00
Daniel Marjamäki 260a214ef1
Fix #11812 (Crash: misra addon, infinite recursion) (#5207) 2023-07-04 04:11:03 +02:00
Daniel Marjamäki 91dedf05b5
Fix #11793 (False positive: Misra addon crash for struct initialization when struct has a function pointer array) (#5190) 2023-06-25 11:37:49 +02:00
Daniel Marjamäki 4cf9a704b4
Fixed #11707 (False positive: misra 9.3 partial array initializations) (#5034) 2023-05-05 17:22:58 +02:00
Daniel Marjamäki 8dbc1b802a misra: fix crash 2022-05-17 22:15:49 +02:00
PeterSchops 7199dde161
Fix issue in misra 9 x (#3409) 2021-08-21 22:01:24 +02:00
Georgiy Komarov 79f59d8f39
misra: Fixed crash with struct fields with unknown types on 9.x rules (#3305)
This fixes the crash on with struct fields containing unknown types
reported on the forum:
https://sourceforge.net/p/cppcheck/discussion/general/thread/d64551cc55/#5f0f

The suggested patch doesn't handle the cases when there are struct
fields with arrays containing unknown types. So the addon will not
generate warnings in these cases. The problem is that Cppcheck doesn't
generate valueType-pointer information for unknown types in the dump
file. When adding this in symboldatabase.cpp, MISRA addon will generate
a lot of false positives because we depend on the null value of
valueType.

So I suppose it better to left this as is, to don't break the addon for
such rare cases.
2021-06-24 08:29:27 +02:00
Ivar Andreas Bonsaksen dc582560cc
Add default parameter to next() to prevent StopIteration exception when no corresponding rawToken is found for '[' token (#3301)
Co-authored-by: Ivar Bonsaksen <ivar.bonsaksen@microchip.com>
2021-06-19 20:24:21 +02:00
Ivar Andreas Bonsaksen e3b7ceec7e
Fix issue where misra 9_x evaluation crashes on some undefined structs with nested initialisers (#3290) 2021-06-04 17:19:40 +02:00
Georgiy Komarov 390a5af064
misra.py: Fix crashes on obsolete GCC syntax for struct initialization (#3175)
* misra.py: Fix crashes on obsolete GCC syntax for struct initialization

* Added expected violations
2021-03-20 13:59:39 +01:00
Oliver Stöneberg b472b4e65d
some Python cleanups based on PyCharm inspections (#2999)
* some Python cleanups based on PyCharm inspections

* test-helloworld.py: adjusted assert in test_addon_relative_path()
2021-01-31 14:27:11 +01:00
Georgiy Komarov 82f51bd523
misra: Fix crash on rule 9.x (#3024)
Closes ticket #10084
2021-01-07 15:04:12 +01:00
kskjerve c22290f5a3
Fix #10043 unexpected designator (#2966) 2020-12-21 13:25:41 +01:00
kskjerve d4860f500a
MISRA 9.2 to 9.5 (#2954) 2020-12-16 17:28:54 +01:00