Commit Graph

42 Commits

Author SHA1 Message Date
chrchr-github 8a7992c6ac
Suppress operatorEqVarError for known non-copyable types (#3869)
* Fix FP operatorEqVarError with class hierarchy

* Suppress operatorEqVarError for std::mutex

* Add test, non-copyable Qt types

* Update cppcheck-cfg.rng
2022-03-03 09:41:26 +01:00
orbitcowboy 1798b73808 cppcheck-cfg.rng: Increased number of allowed function arguments from 20 to 40. Have seen this number of arguments in generated code. 2022-02-03 15:35:09 +01:00
orbitcowboy 76b6203e0d cppcheck-cfg.rng: Allow return values to be started with '::'. 2022-02-03 15:24:30 +01:00
orbitcowboy 0cec93cab7 cppcheck-cfg.rng: Updated pattern that 'char const * const *' is accepted as return type as well. 2022-02-03 14:48:57 +01:00
Daniel Marjamäki 77434d093e SymbolDatabase: Do not set wrong type for std::map etc items in range for loop 2021-12-11 15:16:54 +01:00
Paul Fultz II 8668d445c7
Add support for string_view (#3480) 2021-10-05 08:28:19 +02:00
Paul Fultz II 865163b2ba
Add library configurations for free functions like std::size, std::empty, etc (#3410) 2021-08-23 09:03:48 +02:00
Paul Fultz II 8efe1d4ab4
Find reference to dangling unique ptr (#3344) 2021-07-20 21:30:27 +02:00
Daniel Marjamäki ce58748690 library: add attribute strlen-arg for <not-overlapping-data> 2021-07-09 13:25:01 +02:00
Daniel Marjamäki 6234b5438e New check: Writing overlapping data, detect undefined behavior 2021-07-05 22:07:41 +02:00
Daniel Marjamäki b94a6d595a Fixed #9295 (ValueFlow: Does not handle noreturn function) 2020-12-28 20:00:35 +01:00
orbitcowboy 826609ad95 ginac.cfg: Added configuration for GiNaC (ref. https://www.ginac.de/ ) 2020-12-28 17:38:11 +01:00
Georgy Komarov b75d0665a7
qt.cfg: Add interfaces with new ignoredReturnErrorCode warnings (#2885)
* qt.cfg: Add interfaces with new ignoredReturnErrorCode warnings

* Tweak xmllint configuration
2020-11-06 09:40:44 +01:00
orbitcowboy a3d58a9302 std.cfg: Allow scientific floating point notation for '<valid>'-tags 2020-06-12 08:51:33 +02:00
Sebastian 5cbed0464c
opencv2.cfg: Add types, macros, functions and memory (de)allocation (#2620)
* opencv2.cfg: Add types, macros, functions and memory (de)allocation

* cfg/cppcheck-cfg.rng: Allow alloc/realloc functions in classes
2020-05-30 17:41:44 +02:00
Paul Fultz II a22a77c1fc
Use library config for unstable containers instead of hardcoded values (#2585)
* Use library config for unstable containers instead of hardcoded values

* Fix xml validation
2020-04-03 13:16:57 +02:00
Sebastian b06f4d4189
gtk.cfg/cppcheck-cfg.rng: Add Gtk utility functions, enhance RNG file (#2563)
This adds/fixes some miscellaneous Gtk/Glib utility functions.
Reference:
https://developer.gnome.org/glib/stable/glib-Miscellaneous-Utility-Functions.html
For specifying pointers to pointers as return value types the
cppcheck-cfg.rng has been enhanced to allow this.
2020-02-29 12:11:02 +01:00
Ken-Patrick Lehrmann 9ce2641704 Fix typo in cppcheck-cfg.rng (#2371) 2019-11-17 15:41:04 +01:00
Daniel Marjamäki f5e3dc9a38 Improved fix for #8978 (False positive: Variable assigned value that is never used when assigning via iterator) 2019-11-17 12:08:21 +01:00
Paul Fultz II 4ebf54d090 Fix issue 9437: Dont assume init list constructor for strings (#2366)
* Fix issue 9437: Dont assume init list constuctor for strings

* Update the schema

* Add documentation
2019-11-17 03:22:04 +01:00
Paul Fultz II 7841430793 Fix issue 9428: FP uninitvar for pointer passed to sscanf (#2344)
* Add indirect to library cfg files

* Check indirect for non null arguments

* Reenable subfunction analysis

* Use indirect 1 when using not-null

* Parse correct string name

* Update documentation

* Make attribute optional
2019-11-13 12:46:54 +01:00
Daniel Marjamäki 69a54b0ee9 Library: added 'stdtype' attribute in <podtype> element so we can configure standard types better 2019-09-29 16:48:25 +02:00
Daniel Marjamäki 783f7f1648 Rename safeValues to unknownValues 2019-07-11 16:05:48 +02:00
Daniel Marjamäki 05d35b063d Function return: Extra check of safe function return values 2019-07-10 20:00:21 +02:00
Rikard Falkeborn 839fcddd8a Fix #6115 (Add support to realloc to cfg files) (#1953)
* Allow to configure realloc like functions

* memleakonrealloc: Bring back tests.

The old memleak checker was removed, and the tests for it was removed in
commit 9765a2dfab. This also removed the
tests for memleakOnRealloc. Bring back those tests, somewhat modified
since the checker no longer checks for memory leaks.

* Add realloc to mem leak check

* Add tests of realloc buffer size

* Configure realloc functions

* Add test of freopen

* Allow to configure which element is realloc argument

* Fix wrong close in test

cppcheck now warns for this

* Update manual

* Update docs

* Rename alloc/dalloc/realloc functions

Naming the member function realloc caused problems on appveyor. Rename
the alloc and dealloc functions as well for consistency.

* Change comparisson order

* Remove variable and use function call directly

* Create temporary variable to simplify

* Throw mismatchError on mismatching allocation/reallocation

* Refactor to separate function

* Fix potential nullptr dereference

As pointed out by cppcheck.
2019-07-05 12:44:52 +02:00
Paul Fultz II 091f4bcf8d Add check for unnecessary search before insertion
This will warn for cases where searching in an associative container happens before insertion, like this:

```cpp
void f1(std::set<unsigned>& s, unsigned x) {
    if (s.find(x) == s.end()) {
        s.insert(x);
    }
}

void f2(std::map<unsigned, unsigned>& m, unsigned x) {
    if (m.find(x) == m.end()) {
        m.emplace(x, 1);
    } else {
        m[x] = 1;
    }
}
```

In the case of the map it could be written as `m[x] = 1` as it will create the key if it doesnt exist, so the extra search is not necessary.

I have this marked as `performance` as it is mostly concerning performance, but there could be a copy-paste error possibly, although I dont think thats common.
2019-05-02 11:04:23 +02:00
Daniel Marjamäki 2513c1499b Library: Added <smart-pointer> element 2019-04-24 13:06:58 +02:00
Daniel Marjamäki 55433fce40 Library: added bufferSize parameters 2019-03-20 19:26:57 +01:00
Daniel Marjamäki 14528bcf25 Library: allowed values for the buffer-size attribute: malloc/calloc/strdup 2019-03-20 06:46:55 +01:00
Sebastian 19e9e42dd7
Library: Enhance minsize configuration and allow simple values. (#1736)
Some POSIX and Windows functions require buffers of at least some
specific size. This is now possible to configure via for example this
minsize configuration: `<minsize type="value" value="26"/>`.
The range for valid buffer size values is 1 to LLONG_MAX
(9223372036854775807)
2019-03-17 14:22:26 +01:00
Daniel Marjamäki 18668a52b9 Library: Added buffer-size attribute for <alloc> 2019-03-17 10:55:15 +01:00
Sebastian 9a5fcddb5d
Library configuration: Enable configuring the direction of arguments. (#1717)
This enhances the library configuration so the direction of function
arguments can be specified (in, out, inout).
isVariableChangedByFunctionCall() uses this information now to avoid
guessing.
2019-03-01 15:47:08 +01:00
Sebastian d7e219043a
Library configuration validation: Enhance relaxng file (arg elements) (#1698)
Make sure that the elements of function->arg contain no duplicates.
Except for 'minsize' which can be specified zero to many times.
2019-02-26 14:00:54 +01:00
Sebastian 6a3e1eeef7
Library configuration validation: Enhance relaxng file, fix *.cfg files. (#1685)
This fixes https://trac.cppcheck.net/ticket/8985 at least for the
function configuration.
Errors in configuration files found by the new relaxng file are fixed.
2019-02-22 15:31:52 +01:00
rikardfalkeborn 491ee577c6 Support floats in valid config (#1297)
* Add tests for invalid ranges

* Refactor loadLibErrors

This reduces the amount of code slightly and will simplify adding
more tests.

* Handle empty valid field

Before this change, the sequence <valid></valid> in a config file would
result in a segmentation fault. Now an empty field results in the error
message:

cppcheck: Failed to load library configuration file 'mycfg.cfg'. Bad attribute value '""'

* Add support for valid for floating point arguments

Previously, it was not possible to add valid ranges to floating point
arguments since it only handled integers. This made ranges not work well
for floating point arguments since arguments were cast to integers
before the ranges were handled.

Fix this by using doubles instead of integers if the argument is a float.
Add some tests for this and make sure errors are printed with enough
precision (somewhat arbitrarily chosen).

Note that it is still only possible to add integer ranges (i.e. -1:1).

* Add support for floats in configuration valid range

Now that it is possible to handle decimal arguments, there is no reason
to not allow non-integer ranges. Take care to not allow broken
configurations.

* Move check to within if-clause

* Move asin{,f,l} and acos{,f,l} input checks to config file
2018-07-15 22:47:56 +02:00
Sebastian 80c2074ea7
cppcheck-cfg.rng: Allow return value by reference (#1077) 2018-02-06 08:33:20 +01:00
Daniel Marjamäki 62b84e31ab ValidateCFG: Fix 'valid' pattern 2017-07-28 19:46:55 +02:00
Daniel Marjamäki 7875054f36 Fixed #8078 (cppcheck-cfg.rng outdated) 2017-07-23 12:09:41 +02:00
Daniel Marjamäki 5ee6e082e8 cppcheck-cfg.rng: more strict minsize type value 2015-01-31 10:48:11 +01:00
Daniel Marjamäki 9deffc088d cppcheck-cfg.rng: more strict about values 2015-01-31 08:08:39 +01:00
Daniel Marjamäki 0c89afcc48 cppcheck-cfg.rng: more strict about 'format' and 'valid' 2015-01-29 07:28:40 +01:00
Daniel Marjamäki 7d0f5ad7c1 cfg: added cppcheck-cfg.rng schema that cfg files can be validated against 2015-01-28 07:39:08 +01:00