Commit Graph

683 Commits

Author SHA1 Message Date
Maarten van der Schrieck 21a9de7d42
addons/namingng.py: Reinstate dict-with-regexps, cosmetic overhaul. (#5824)
`namingng.py` somewhat supported specifying a dict instead of a list for
regular expressions, until the feature was broken by a patch of mine
recently. This PR contains a patch rewriting the feature and expanding
relevant unit tests.

To improve maintainability, a second patch is added that refactors the
code for better readability and structure.
2024-01-04 16:26:54 +01:00
thingsconnected 8261ded475
addons/namingng.py: Improve output and unit test. (#5820)
For naming issues reported, column was always set to `0`, which is now
fixed.

Global variable naming errors were reported as "Public member" issues,
which is also fixed.

The unit test now covers namespaces, class names, public and private
member variables.
2024-01-03 14:00:47 +01:00
thingsconnected 98b9244bcb
addons/namingng.py: Add tests for include guards, config file validation. (#5815)
Include guard naming can be validated against various patterns:
- prefixes/suffixes (`_FILE_H`, `PROJECT_FILE_H`, `FILE_H_`)
- basename/full path (`FILE_H`, `SUB_DIR_INC_FILE_H`)
- upper- or lowercase (`FILE_H`, `file_h`)
- any combination of the above (`project_sub_dir_inc_file_h_`)

A regexp can be specified to match header filenames. The example matches
any filename not starting with / and ending with `.h`, intended to match
C header files while exluding system files.

The test is not limited to naming only; validity and presence of include
guards can also be tested by setting `"required":true` in the config
file.

Enabling this feature requires adding the key `"include_guard"` to the
namingng config file used.

The namingng unit test is extended to test various features of the
include guard test.

Also, config handling is improved, adding (superficial) validation and a
unit test.
2024-01-02 15:01:02 +01:00
thingsconnected 24133d4a59
addons/namingng.py: Fix commandline use. (#5793)
namingng.py was only usable in standalone mode, but now supports CLI
mode, i.e. with cppcheck --addon=namingng. It uses the generic reporting
provided by cppcheckdata.reportError(). All output other than reported
errors is suppressed.

A local function reportNamingError() is implemented to call through to
cppcheckdata.reportError(), filling in common defaults.

The collection of errors and the --verify feature are removed, including
related workflow and a test file. These are replaced by a unit test.
2023-12-30 20:54:03 +01:00
Swasti Shrivastava 681b15f5c9
Fix #12298: false positive: misra-c2012-9.3 (#5812) 2023-12-30 13:05:25 +01:00
thingsconnected 4c7aae3a16
addons/namingng.py: Improve file name checking feature. (#5802)
(note: comment updated after force push; initial PR was incomplete)

namingng.py attempted to derive the source filename from the name of the
dumpfile. However, the dumpfile is not necessarily named according to
this pattern, e.g. cppcheck will add the pid to the filename, making
RE_FILE rules
fail. Taking the first item of data.files seem to be more robust.

To get the basename of the file, `os.path.basename()` is used. This
solves (theoretical) issues on platforms with a different path
separator.

With this patch, all filenames are checked, not just those provided on
the cppcheck command line. This is useful as header files will now also
be part of this check, even if not explicitly specified on the command
line.

The "RE_FILE" key of the configuration JSON may contain a list of
regular expressions, where any match will lead to acceptance of the
filename.

Both the full path and the basename of the files are tested.

One use case for this combination of features is:

```
"RE_FILE":[
    "/.*\\.h\\Z",
    "[a-z][a-z0-9_]*[a-z0-9]\\.[ch]\\Z"
]
```
This will accept any file naming convention of the platform used
(assuming platform files are all referenced using an absolute path),
while enforcing a particular naming scheme for project files.
2023-12-27 18:56:29 +01:00
thingsconnected d506e7e937
addons/namingng.py: allow function/variable name test without prefixes (#5801)
This patch allows a config file to have RE_VARNAME and RE_FUNCTIONNAME
without the corresponding var_prefixes and function_prefixes keys. The
namingng.py processing function would otherwise raise an exception
trying to get these keys, while they are not strictly necessary, if no
prefixes are required.
2023-12-23 22:33:36 +01:00
Eric Sesterhenn 3b1c701766
fix casing in variable name (#5778)
The attribute movedValue is misspelled with an uppercase V, this leads
to errors when printing token values:

```
$ python3 runaddon.py test.py test.c.dump 
Checking test.c.dump...
Checking test.c.dump, config ...
line 2 str=""lala\n""
Traceback (most recent call last):
  File "/home/eric/tools/cppcheck/addons/runaddon.py", line 11, in <module>
    cppcheck.runcheckers()
  File "/home/eric/tools/cppcheck/addons/cppcheck.py", line 39, in runcheckers
    c(cfg, data)
  File "test.py", line 9, in func
    print(f'    {value}')
  File "/home/eric/tools/cppcheck/addons/cppcheckdata.py", line 907, in __repr__
    ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
  File "/home/eric/tools/cppcheck/addons/cppcheckdata.py", line 907, in <genexpr>
    ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
AttributeError: 'Value' object has no attribute 'movedValue'
```
2023-12-18 18:57:08 +01:00
Daniel Marjamäki 22613dc7fb
Fixed #12267 (Misra.py: crashes in 17.7 checker when there is macro in variable declaration) (#5768) 2023-12-15 22:53:19 +01:00
Swasti Shrivastava db66105128
Fix #10854: False positive: misra-c2012-9.2: inner union (#5693) 2023-11-27 18:28:53 +01:00
Daniel Marjamäki 727d086dc4
Fix #12217 (misra 11.4: report conversion in macro) (#5692) 2023-11-22 12:47:48 +01:00
andymacg f444696d5c
Fix #12198: Expect function pointers in Misra 17.7 check (#5675) 2023-11-20 20:19:20 +01:00
Swasti Shrivastava 1ce901385a
Fix #12172:False positive: misra-11.1 function pointer assigned to array (#5667) 2023-11-16 13:57:27 +01:00
Swasti Shrivastava 81a03e7341
Fix #12184: false positive: misra 11.6, cast expression '0U' to 'void*' (#5666) 2023-11-16 09:06:58 +01:00
Daniel Marjamäki 282c195a6f
Fix #12169 (False positive: wrong misra-config variable with accessing object in memory) (#5645) 2023-11-09 12:25:42 +01:00
Daniel Marjamäki 617b7a39cd
Fix #12163 (misra.py: crashes when ctu-info line does not have certain attributes) (#5638) 2023-11-08 15:23:50 +01:00
Swasti Shrivastava 12844703de
Fix #9488: MISRA addon: False positive for rule 10.6 in test for rule 10.1 (#5598) 2023-10-30 17:24:19 +01:00
Swasti Shrivastava 915b4b6c5a
Fix #10747: FP: misra-c2012-8.6 (#5601) 2023-10-29 19:39:36 +01:00
Swasti Shrivastava 56bfa9f3ea
Fix #9498: false positive: misra-c2012-18.8 (#5600) 2023-10-28 18:45:40 +02:00
Daniel Marjamäki 083c4aa34b
Fix #12079 (Make misra-config a critical error) (#5578) 2023-10-28 16:58:59 +02:00
Swasti Shrivastava 689187d82a
Fix #12020: misra-test.c: wrong syntax in some test cases (#5597) 2023-10-26 18:37:44 +02:00
Swasti Shrivastava b58a6b6911
Fix #11474, #9491: FP: misra-c2012-14.2 (#5582) 2023-10-23 08:51:47 +02:00
Swasti Shrivastava 04ece4f65b
Fix #12079: Misra: calling unknown function in condition => false pos… (#5568)
…itive 14.4, missing misra-config warning
2023-10-19 19:38:20 +02:00
Swasti Shrivastava ad4e688ff8
Fix #10652: FP: misra-c2012-10.4 (char)'1' != (char) (#5556) 2023-10-16 18:53:51 +02:00
Swasti Shrivastava dde956b085
Fix 10855,11752:False positive: misra-c2012-22.10 (#5557) 2023-10-15 17:33:35 +02:00
Daniel Marjamäki cc44966fb5
std.cfg: remove wrong macro replacements for UINT32_C etc. (#5527)
The replacements should be platform dependent.
2023-10-08 14:44:07 +02:00
Oliver Stöneberg a3ff6d53c4
added `-Werror` to pytest calls and fixed reported warnings (#5483) 2023-09-26 15:31:37 +02:00
Oliver Stöneberg 1959c85e34
test/cli/test-other.py: improved addon tests (#5469) 2023-09-25 13:39:17 +02:00
Oliver Stöneberg a43b55a0ca
Improved addon execution errorhandling (#5451) 2023-09-20 10:40:57 +02:00
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