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.
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.
As reported in
https://sourceforge.net/p/cppcheck/discussion/general/thread/fa43fb8ab1/
removeContradiction() minValue/maxValue.remove(..) can access free'd
memory as it removes all matching values by iterating over the complete
list. Creating a full copy instead of a reference avoids this issue.
Signed-off-by: Dirk Müller <dirk@dmllr.de>
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'
```
The handling in `CppCheck::reportErr()` and `Executor::hasToLog()` was
slightly different. I hope this can somehow be shared after the executor
reworking.
We were also using a very inappropriate container for the error list
which caused a lot of overhead.
`-D__GNUC__ --debug-warnings --template=daca2 --check-library -j2
../test/testsymboldatabase.cpp`
Clang 15
main process `284,218,587` -> `175,691,241`
worker process `9,123,697,183` -> `8,951,903,360`