Commit Graph

145 Commits

Author SHA1 Message Date
Oliver Stöneberg 42c3aebda9
AddonInfo: const-ified loading and improved errorhandling (#5834) 2024-01-05 15:01:02 +01:00
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
thingsconnected 403e7f1f7d
lib/addoninfo.cpp: When loading a JSON addon, test 'script' key. (#5797)
In case a user accidentally uses a wrong JSON file (e.g. naming.json,
which is the config file for namingng.py), the code could give a
confusing exception. This happens when the key 'script' is not defined
as a string.

This is solved by testing the key for existence and type. In case
'script' is not a key or refers to a type other than a string, a clear
error is given, stating for example: 'Loading naming.json failed. script
must be set to a string value.'

The message is kept in line with other messages. Maybe it can be
clarified further, e.g. 'Loading naming.json failed. A key "script" must
be set with a string value referring to a Python script.' - in which
case the errors relating to other keys may also be clarified.
2023-12-25 05:49:17 +01:00
Daniel Marjamäki 49da3e3821
Fixed #12281 (IDE plugin integration is broken by checkers report) (#5779) 2023-12-19 15:55:29 +01:00
Daniel Marjamäki 5aa1710dd0
Fix #12071 (Add safety mode that makes cppcheck more strict about critical errors) (#5777) 2023-12-18 18:26:23 +01:00
Daniel Marjamäki 2932ab7592
Revert "Fixed #12071 (suppressing critical error, no indication to user that analysis of file fails) (#5771)" (#5775)
This reverts commit 7c316fb76d.
2023-12-17 19:13:14 +01:00
Daniel Marjamäki 7c316fb76d
Fixed #12071 (suppressing critical error, no indication to user that analysis of file fails) (#5771) 2023-12-17 15:42:17 +01:00
Oliver Stöneberg 086ceea333
fixed #12111 - memory leak with `-j2` and `--cppcheck-build-dir` (#5589) 2023-12-17 15:07:13 +01:00
Oliver Stöneberg f2622a673f
more cleanups in handling of ignored files (#5767) 2023-12-16 21:04:45 +01:00
Oliver Stöneberg 1135520aa8
run more tests in sanitizer workflows (#5744) 2023-12-16 17:03:03 +01:00
chrchr-github 02fed7a266
Fix #12235 performance regression (hang) in 2.13dev (#5715)
Co-authored-by: chrchr-github <chrchr@github>
2023-12-15 11:01:08 +01:00
Oliver Stöneberg fcb41e2533
small cleanup of handling of ignored paths (#5757) 2023-12-14 16:55:42 +01:00
Oliver Stöneberg 7452e681dd
fixed #12221 - de-duplicate input source files (regression) (#5740) 2023-12-08 22:17:22 +01:00
Daniel Marjamäki 70745b527a
Fix #12210 (Cppcheck hang in SymbolDatabase::createSymbolDatabaseExprIds) (#5699) 2023-12-05 14:22:32 +01:00
Daniel Marjamäki 56c7ac3771
Fix #12182 (speedup valueFlow by only running valueFlowNumber once) (#5678) 2023-11-19 18:56:48 +01:00
Daniel Marjamäki e01e090f1c
Fix #10866 (no preprocessorErrorDirective and code generated in case of unconditional #error) (#5670) 2023-11-16 17:25:49 +01:00
Oliver Stöneberg 682901ac2a
fixed #10760 - added file name to ValueFlow `--debug` output (#5655) 2023-11-16 13:44:50 +01:00
Oliver Stöneberg b0cde34d1a
refs #12167 - moved ordering of markup files into shared code / removed related test cases from executor tests (#5642)
This is not completely fixing the issue yet. `test-qml.py` still fails
when using multiple threads.
2023-11-09 10:17:30 +01:00
Oliver Stöneberg bc174c502a
fixed #12145 - provided order of source files is not preserved (#5625) 2023-11-07 21:21:24 +01:00
Oliver Stöneberg 704b862a2d
cleaned up the file filtering code and improved testing of it (#5622) 2023-11-06 19:06:22 +01:00
Daniel Marjamäki 0dc53ac7fe
Fix #12144 (Error messages from addons has the wrong file0) (#5621) 2023-11-04 17:07:30 +01:00
Oliver Stöneberg cc92b09ec1
fixed #12016 - ProcessExecutor: added missing invocation of clang-tidy (#5529)
No changes in tests since the intercepted invocation function in called
in a forked process. The clang-tidy integration is also broken.
2023-10-09 12:26:58 +02:00
Oliver Stöneberg 0f28f3e493
generate `AddonInfo` only once (#4958)
Currently the `AddonInfo` is generated and discarded on each addon
invocation. This leads to an unnecessary process invocation for each
addon on each file.

Also if an addon is completely broken we will still perform the whole
analysis only for it to be failed at the end so we should bail out early
if we know it doesn't work at all.
2023-10-08 21:28:57 +02:00
Oliver Stöneberg fc700b68eb
refs #4452 / refs #11705 - improved `--showtime=` behavior and testing (#4876)
This is a step onto leveraging the `ThreadExecutor` implementation for
`ProcessExecutor` which is a follow-up to #4870. We need to have the
proper test coverage and the existing implementations working as
expected before we move to the shared code.

Fixes:
- added `--showtime=` tests for all executor implementations
- only print `--showtime=summary` once at the end
- prevents `--showtime=` by multiple threads to be written at the same
time - essentially breaking the output
- reset the timer results before each test
- deprecated `top5` in favor of `top5_file`
- fixed printing for all executors except `ProcessExecutor`
2023-10-05 19:04:06 +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 f49fedb2ad
fixed #11483 (FN unusedFunction for method with inline implementation) (#5457)
Co-authored-by: chrchr-github <78114321+chrchr-github@users.noreply.github.com>
2023-09-20 14:45:44 +02:00
Oliver Stöneberg a43b55a0ca
Improved addon execution errorhandling (#5451) 2023-09-20 10:40:57 +02:00
chrchr-github 775af5ec70
Add test for simplecpp#314 (#5438) 2023-09-14 09:41:39 +02:00
Oliver Stöneberg 64cd09ab62
fixed #11917 (Default to `native` platform in Windows builds) (#5428) 2023-09-11 11:08:23 +02:00
Oliver Stöneberg 91070ca794
utils.h: added `startsWith()` and started using it (#5381)
This makes the code much more readable. It also makes it less prone to
errors because we do not need to specify the length of the string to
match and the returnvalue is clear.

The code with the bad returnvalue check was never executed and I added a
test to show that.
2023-09-08 19:30:25 +02:00
Daniel Marjamäki 22547beaaf
CI: Add test for #11649 (#5380) 2023-08-31 16:46:20 +02:00
Oliver Stöneberg ad1caa8100
report `internalError` when command execution returns errorcode / also some related cleanups and tests (#5037)
Encountered while investigating https://trac.cppcheck.net/ticket/11708.

This has been like this since the introduction of `internalError` in
b6bcdf2936 (almost ten years ago to the
day). Logging internal errors which bail out(!) of the analysis simply
to `std::cout` for them possibly never to be seen (and also not affected
the exitcode) is pretty bad IMO. They should always be visible.

I also removed the filename from the message as it is already available
(and thus redundant) and its existence should be defined by the
template.
2023-08-31 13:33:29 +02:00
Daniel Marjamäki 7c992ced4c
Fixed #11901 (Performance regression: large array with strings) (#5375)
Analysis has slowed down a lot when there are many strings in an array.
2023-08-30 19:35:43 +02:00
Daniel Marjamäki 276f017fbe
Partial fix for #11897 (Safety: show what checks are enabled/disabled) (#5372)
Example output on stdout:
```
$ ./cppcheck m1.cpp 
Checking m1.cpp ...
Active checkers: 59/177
```
2023-08-29 12:00:52 +02:00
Oliver Stöneberg 0901e496ed
refs #3450 (CLI --report-progress is currently useless) - added `--report-progress=<val>` to specify interval (#5353) 2023-08-23 11:20:20 +02:00
Oliver Stöneberg 59c3bd22e6
ProcessExecutor: removed unnecessary `\0` passing in message reading/writing - fixes stray `\0` characters in output (#5354)
This was introduced in #5279. We were transferring the terminating `\0`
via the pipe and also added another one in the parsing. As we are now
directly writing into a `std::string` these extra characters will now
show up in it. So just get rid of them.
2023-08-21 12:17:08 +02:00
Oliver Stöneberg cc592a6927
CppCheckExecutor: improved library loading error handling a bit (#5275) 2023-08-07 19:48:11 +02:00
Daniel Marjamäki 7840bc4c63 Execute runformat 2023-06-10 17:37:32 +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
chrchr-github bc03bed075
#11733 FP unusedFunction with templates and --cppcheck-build-dir (#5085)
* #11733 FP unusedFunction with templates and --cppcheck-build-dir

* Add test
2023-05-26 06:13:48 +02:00
Daniel Marjamäki e8233ceb67 runformat 2023-05-08 10:30:20 +02:00
Daniel Marjamäki 46b9d4ec61
Fixed #11700 (Markup support is broken, unused function false positives) (#5025) 2023-05-03 11:19:13 +02:00
Oliver Stöneberg ad464c4feb
Preprocessor: relaxed dependency on `Suppressions` (#4983)
* Preprocessor: cleaned up `missingInclude()`

* Preprocessor: relaxed dependency on `Suppressions` / adjusted `TestPreProcessor::inline_suppression_for_missing_include()` which was not testing production behavior

* test/cli/test-other.py: added test for `missingInclude` and `missingIncludeSystem` inline suppressions

* fixed `constParameterReference` selfcheck warning
2023-04-21 10:14:34 +02:00
Daniel Marjamäki f52c00c3a7 fixed CI. I remove dump files in cppcheck build dir after analysis. 2023-04-07 19:02:34 +02:00
Oliver Stöneberg 7fd4118d60
Fix #10039 (integrate `--check-config` include findings with normal analysis) / also fixes #11283 (#3229) 2023-03-04 09:02:35 +01:00
Michael Drake d651b6baf1
dump: Fix concurrency problem with dump files (#4757)
* dump: Fix concurrency problem with dump files

This adds the process ID for the cppcheck process to the filenames
of the .dump and .ctu-info files that the process generates.

So
  lib/cppcheck.cpp.dump
becomes
  lib/cppcheck.cpp.<PID>.dump

For example:
  lib/cppcheck.cpp.2637871.dump

The reason for this change is that if there is a buildsystem which
supports concurrency, multiple instances of cppcheck may be run for
the same file.  For example, if the same file is compiled in multiple
build variants, or for multiple targets.

If running the MISRA plugin over such a project with concurrency
enabled in the buildsystem, the plugin ends up crashing as multiple
jobs attempt to create/trample/delete the same files while other
jobs are using them.

For more information see:
    https://sourceforge.net/p/cppcheck/discussion/general/thread/02c757b4af/

* dump: Include pid in filename if dump not explicit

Only change the dump and ctu-info filenames to include the PID if
they are being generated due to an addon.

This means that existing scripts that use `--dump` will still work
if they depend on the previous naming behaviour. The more robust
filenames containing the pid will be used when the dump files are
used as an internal implementation detail for passing data to addons.

However this means that anything that does explicitly use `--dump`
will be susceptible to concurrency problems.

* test: Update addon dump file test to account for pid

This test causes a dump file to be created by enabling the misra
addon. Since the dump files now include the cppcheck process pid
this test had to be updated to account for the change.
2023-02-13 20:54:21 +01:00
Oliver Stöneberg 14e78e1800
greatly improved error handling in Cppcheck project file parsing / some cleanups (#4752) 2023-02-08 20:30:43 +01:00