Commit Graph

654 Commits

Author SHA1 Message Date
Daniel Marjamäki 204e75dc59
Fixed #11909 (misra addon: rule 1.2 detect some gcc language extensions) (#5390) 2023-09-01 16:44:14 +02:00
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
Daniel Marjamäki 18b526b08a
CI: Fix selfcheck cppcheck warnings (#5359) 2023-08-22 14:49:08 +02:00
andymacg 5a136c3f38
Fix #11877 FP misra 10.4 On array member comparison (#5342)
I also changed the comment header to run tests on misra-test-avr8.c
because I thought that was the intention to use it like misra-test.c; if
not, I can revert.
2023-08-22 12:18:12 +02:00
andymacg 5bb4c6f5bc
Fix #11878 FP misra-c2012-18.7 on function pointer parameter with array-type args (#5343)
https://trac.cppcheck.net/ticket/11878#ticket
2023-08-22 12:03:12 +02:00
chrchr-github 7f22ef4e14
Set ValueType for auto with ternary (#5304) 2023-08-18 10:33:26 +02:00
Oliver Stöneberg 5a322365a6
fixed `scriptcheck.yml` (#5268) 2023-08-01 13:06:12 +02:00
Daniel Marjamäki 3508464c6d
dump: fix dump output for typedef info, file is <stdout> (#5236) 2023-07-12 11:21:59 +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
PeterSchops b689ca8d89
Update cppcheckdata.py (#5149)
* Update cppcheckdata.py

- added links to cpp-file/function that writes this part of the dump-file 
- updated documentation (Added list of possible return values for a number of variables) 
- added MacroUsage isKnownValue 
- added ValueType reference 
- added Token isBoolean 
- added Token isCast 
- added Token externLang 
- added Token isComplex 
- added Token isRestrict 
- added Token isAttributeExport 
- added Token originalName 
- added Scope functions 
- added Scope definedType 
- added Function hasVirtualSpecifier 
- removed Function isVirtual 
- added Function isAttributeNoreturn 
- added Function overriddenFunction 
- added Variable isVolatile 
- class Container added 
- added Value movedValue 
- added Value uninit 
- added Value bufferSize 
- removed Value inconclusive and added it to valueKind

* Update cppcheckdata.py

removed encoding from open (needed to make python 2.7 check pass) where python 2.7 should not be used anymore

* Update cppcheckdata.py after feedback

made sure that attributes I added to the class always have a value
added some missing attributes in the print
2023-06-15 20:42:58 +02:00
Long Radix c033c62190
Typos and stilistic updates (#5141) 2023-06-14 12:30:45 +02:00
Daniel Marjamäki d4902109cd
threadsafety.py: cleanup (#5132) 2023-06-08 19:58:11 +02:00
Andrew C Aitchison 0727528876
The threadsafety.py addon now flags MT-Unsafe symbols and functions. (#5086) 2023-06-08 14:46:09 +02:00
Daniel Marjamäki 520a6644a6
y2038.py: some fixes for obsolete code in y2038.py (#5131) 2023-06-08 14:44:05 +02:00
Daniel Marjamäki 6b9fac41f4
Fixed #11734 (stylistic warnings from addons are not filtered when style is not enabled) (#5091) 2023-05-27 10:24:00 +02:00
Daniel Marjamäki 2cb4c4126a
Fix #11443 (FP: misra-c2012-5.7 on anonymous struct) (#5033) 2023-05-07 20:22:26 +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 029056b0b4 misra.py: Add safety check 2023-04-17 17:21:02 +02:00
Swasti Shrivastava e575a84c8a
Update misra.py to not run a few rules for cppcheck premium (#4970) 2023-04-15 18:35:34 +02:00
apuly 30ff1aad9a
misra: fix misra-3_1 false positive for URIs in block comments (#4939)
* misra: fix misra-3_1 false positive for URIs in block comments

* added unit test, improved new misra 3.1 based on false positives

---------

Co-authored-by: Paul B <unconfigured@null.spigotmc.org>
2023-04-11 16:13:10 +02:00
tx_haggis c0d9a76dd9
MISRA: Speed up analysis of .ctu_info files (#4666)
* Speed up analyses of .ctu_info files
Use temporary dictionaries to eliminate duplicate typedefs,
tags and macros

* Consistency: use a cache key variable
Ensures that the get and add use the same key.

* CTU perf: use dict for macros, tags & types.
2023-04-11 14:20:58 +02:00
Daniel Marjamäki 7cded1967d misra.py: Fix mistake I saw when looking at the code 2023-04-09 18:55:47 +02:00
Daniel Marjamäki 5830047fcb misra: fix misra-10.7 false positive for constant expression 2023-01-02 18:52:33 +01:00
Oliver Stöneberg 0c95971c54
added .gitattributes and normalized files (#4668) 2022-12-30 21:33:45 +01:00
dzid26 3887d6dde1
Missing rule-text-file to not stop the analysis (#4458) 2022-09-12 12:55:07 +02:00
Daniel Marjamäki 514278e02b Fixed #11181 (cppcheckdata.py: handle exception when ctu-info file is missing) 2022-08-25 11:10:39 +02:00
Daniel Marjamäki 0d9bf03b5c misra.py: do not execute premiumaddon to perform misra checks 2022-08-25 08:07:22 +02:00
g-chauvel be658e2392
misra_14_2 various fixes (#4324) 2022-08-21 20:11:10 +02:00
Paul Fultz II 72c764b034
Expose exprId to addon (#4354) 2022-08-16 22:00:31 +02:00
Paul Fultz II a8c1cdca57
Add ** to match until in addons (#4353) 2022-08-16 19:05:37 +02:00
Paul Fultz II 754250cd57
Add methods to token class in addons (#4320) 2022-07-30 11:09:22 +02:00
Daniel Marjamäki 13c80d6cce Fixed #11180 (False positive: misra-c2012-8.1 for code 'unsigned x;') 2022-07-28 20:34:56 +02:00
Oliver Stöneberg bc58f55c6e
donate-cpu: greatly improved `LibraryIncludes.get_libraries()` performance / some optimizations and cleanups (#4273)
* donate_cpu_lib.py: use `os.path.join()`

* donate-cpu: removed remaining usage of `os.chdir()`

* donate_cpu_lib.py: moved library includes code into class

* donate_cpu_lib.py: pre-compile library include regular expressions

* donate_cpu_lib.py: pre-compile some more regular expressions

* donate_cpu_lib.py: small unpack_package() cleanup and optimization

* donate_cpu_lib.py: added some information about the extracted files to unpack_package()

* donate_cpu_lib.py: bumped version

* added test_donate_cpu_lib.py

* donate_cpu_lib.py: greatly improved `LibraryIncludes.get_libraries()` performance

only scan each file once for previously undetected libraries only

* test_donate_cpu_lib.py: fix for Python 3.5

* scriptcheck.yml: added `-v` to pytest calls so we get the complete diff on assertions

* fixed `test_arguments_regression()` Python tests with additional pytest arguments

* donate_cpu_lib.py: use `subprocess.check_call()`

* test_donate_cpu_lib.py: sort results to address differences in order with Python 3.5
2022-07-13 21:09:29 +02:00
Paul Fultz II 7b549b622f
Add match function to addons (#4268) 2022-07-12 22:00:15 +02:00
Daniel Marjamäki e0bc871bae misra.py: strip error message so it does not end with \r 2022-07-08 16:11:15 +02:00
Daniel Marjamäki e64e5811ab misra.py: better handling of --get-rule-text 2022-07-08 14:06:27 +02:00
Daniel Marjamäki ef33ff628f cppcheckdata.py: fix cmd_output() function, handle errors better 2022-06-16 14:07:14 +02:00
Daniel Marjamäki 9e31d6d05d Revert "cppcheckdata.py: better handling when subprocess call fails"
This reverts commit 1cc3b46d32.
2022-06-15 19:38:40 +02:00
Daniel Marjamäki 1cc3b46d32 cppcheckdata.py: better handling when subprocess call fails 2022-06-15 17:13:14 +02:00
Daniel Marjamäki 359f6b3680 misra: enable more checks for misra c++ 2008 checking 2022-06-07 20:55:55 +02:00
Daniel Marjamäki ec13f5fe5c misra: When checking C++ code only activate certain misra c++ compliant rules. It will be supported to run the addon on C++ code. 2022-06-06 22:22:52 +02:00
Alon Alexander ea3bb8b297
Ignore copy/move constructors for function naming checks (#4134)
* Ignore copy/move constructors for function naming checks

* Also change in namingng

* Add test in naming_test.cpp
2022-06-01 06:54:31 +02:00
Daniel Marjamäki 8dbc1b802a misra: fix crash 2022-05-17 22:15:49 +02:00
Daniel Marjamäki 9b807ba047 misra: fix problems when executing premium addon 2022-05-05 14:15:09 +02:00