Commit Graph

142 Commits

Author SHA1 Message Date
Daniel Marjamäki b3f9df968b Uninitvar: fixed 'make checkcfg' 2021-10-03 20:32:39 +02:00
Paul Fultz II 7f358b2bed
Format with uncrustify (#3388) 2021-08-07 20:51:18 +02:00
Daniel Marjamäki 22ae4543a6 Fixed 'make checkcfg' 2021-05-22 07:39:27 +02:00
Daniel Marjamäki 6a0a2456b5 make checkcfg; temporarily disable suppressions 2021-05-16 22:48:22 +02:00
Daniel Marjamäki 45eb9f82a0 Fix CI; Cppcheck find some more unusedAllocatedMemory violations in test/cfg/.. 2021-05-13 23:08:58 +02:00
orbitcowboy f62d9d5853 std.cfg: Fixed bufferAccessOutOfBounds false negative for strncmp(). 2021-04-13 19:13:00 +02:00
orbitcowboy 03bdcc4c42 Attempt to make CI happy 2021-04-13 16:57:31 +02:00
orbitcowboy 040e58f943 std.cfg: strxfrm(): Added minize values to arg1 and arg2 and a TODO test case 2021-04-13 14:07:45 +02:00
Daniel Marjamäki 9ce0235e8e std.cfg: Fixed configuration of mbstowcs 2021-04-03 10:42:24 +02:00
Jens Yllman a87686911a one more test updated for the new checkLibraryFunction 2020-06-23 09:06:54 +02:00
orbitcowboy a3d58a9302 std.cfg: Allow scientific floating point notation for '<valid>'-tags 2020-06-12 08:51:33 +02:00
orbitcowboy e767bb8ff3 std.cfg: Added tests for 'atanh' 2020-06-11 15:13:19 +02:00
orbitcowboy 0fe0e56986 std.cfg: Added tests for 'acosh' 2020-06-11 15:07:35 +02:00
orbitcowboy 4880f30dc3 std.cfg: Added tests for 'aligned_alloc' 2020-06-10 19:33:22 +02:00
orbitcowboy e1eb7e04b5 std.cfg: Added <not-bool/>-flags for some functions from <cwctype> 2020-02-22 14:24:14 +01:00
orbitcowboy a62ddc6edd std.cfg: Added <not-bool/>-tag to isblank() function arg. 2020-02-22 09:43:15 +01:00
orbitcowboy be96abc21a std.cfg: Added <not-bool/>-tags to <cctype> function args. 2020-02-22 09:39:21 +01:00
Armin Müller 130ebe4b85 Typos found by running "codespell" (#2380) 2019-11-19 20:02:24 +01:00
orbitcowboy 2ff18b76ec test std.cfg: Improved tests for strncpy and strrchr . 2019-11-18 13:53:42 +01:00
orbitcowboy d5d2915873 test std.cfg: Improved tests for strncmp and strncat. 2019-11-18 13:43:49 +01:00
orbitcowboy dbbb7f544a test std.cfg: Improved strlen() tests. 2019-11-14 16:45:27 +01:00
orbitcowboy ea92695e54 test std.cfg: Improved sscanf() tests. 2019-11-14 16:38:30 +01:00
orbitcowboy ade54bef3f test std.cfg: Added better tests. 2019-11-14 10:48:23 +01:00
orbitcowboy dd30f37642 std.cfg: Merged 'wcscmp' and 'strcmp' configurations and added better tests. 2019-11-14 08:43:31 +01:00
orbitcowboy 20e2c513b6 test std.cfg: Added better test cases for toupper() and tolower(). 2019-11-14 08:31:00 +01:00
orbitcowboy 09eaa412b1 std.cfg: Improved cfg for 'mbstowcs' 2019-11-13 16:55:17 +01:00
orbitcowboy aa5c42ffc5 test std.cfg: Addressed comments from 177eed122a (comments) 2019-11-13 15:07:57 +01:00
orbitcowboy 177eed122a std.cfg: Added 'indirect' flag for destination argument of 'mbstrtowc' function. 2019-11-13 14:34:02 +01:00
orbitcowboy 7c48874793 #9347: Added a robustness test for scanf 2019-10-17 17:50:26 +02:00
Sebastian e24008544e
test/cfg/std.c: Add nullPointer tests for vsnprintf() (#2262)
Related tickets:
https://trac.cppcheck.net/ticket/9408
https://trac.cppcheck.net/ticket/9410
2019-10-11 20:00:10 +02:00
Paul Fultz II ba037837c9 Track lifetime across multiple returns
This will now warn when doing something like this:

```cpp
template <class T, class K, class V>
const V& get_default(const T& t, const K& k, const V& v) {
    auto it = t.find(k);
    if (it == t.end()) return v;
    return it->second;
}
const int& bar(const std::unordered_map<int, int>& m, int k) {
    auto x = 0;
    return get_default(m, k, x);
}
```

The lifetime warning is considered inconclusive in this case.

I also updated valueflow to no tinject inconclusive values unless `--inconclusive` flag is passed. This creates some false negatives because library functions are not configured to not modify their input parameters, and there are some checks that do not check if the value is inconclusive or not.
2019-09-11 19:25:09 +02:00
orbitcowboy 1994cbbb9c std.cfg: Improved configuration for mbrlen() and extended test cases. 2019-08-27 08:18:19 +02:00
Rikard Falkeborn 8cd1d5a47d Use library for memleak checks (#2002)
* Use library for memleak checks

Change memleakOnRealloc and leakReturnValNotUsed to use library
configuration instead of hardcoding "realloc".

In order to do so, some care needs to be taken when matching for a
reallocation function, since it can no longer be assumed that the input
to be allocated is the first argument of the function. This complicates
getReallocationType() and checkReallocUsage() but is necessary in order
to handle for example freopen() properly.

Also, refactor memleakOnRealloc check to reduce duplicated code when
checking "a" and "*a". When doing so, extending the check to look for
arbitrary number of "*" can be done for free (just change an if
statement to a while statement). Most likely, this is an unusual case in
real world code.

* Remove redundant whitespace in Token::Match()

* Run on simplified checks

* Fix cppcheck warning
2019-07-22 10:37:36 +02:00
Rikard Falkeborn 2bd026dd2a Add tests of std.cfg buffer size (#1958)
Includes a testcase for trac ticket #1379 which was fixed in
839fcddd8a.
2019-07-06 08:55:17 +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
Rikard Falkeborn 60a213e6a5 Fix #9047 (c-style casts before malloc) (#1930)
* Fix #9047 (c-style casts before malloc)

Note that there are still no warnings for c++-style casts

* Fix memleak check with casts of assignments in if-statements

* Fix possible null pointer dereference

As pointed out by cppcheck.

* Add check of astOperand2 when removing casts

This is similar to how it is done in other checks.
2019-07-03 08:39:44 +02:00
orbitcowboy 4a9176f83c std.cfg: Added a test for tmpfile(). 2019-05-17 16:02:48 +02:00
versat 316475f79f std.cfg: Add "buffer-size" attribute and tests for aligned_alloc(). 2019-03-21 09:25:42 +01:00
Daniel Marjamäki 34a8b2b519 Quick fix for 'make checkcfg' 2019-03-16 18:17:16 +01:00
Daniel Marjamäki 27d750b3a1 Travis: Fix 'make checkcfg' 2019-03-11 13:43:15 +01:00
versat df73f7f355 std.cfg, windows.cfg: Move strcpy_s from windows.cfg to std.cfg.
strcpy_s belongs to the standard so it must be in std.cfg instead of
windows.cfg.
Configuration for strcpy_s has been improved and tests were added.
Found by daca@home
2019-03-05 15:33:16 +01:00
Sebastian 0934577dda
Library configuration: function argument direction fixes and enhancements (#1722)
* std.cfg: Add further argument directions (in, out, inout).

* testlibrary.cpp: Add test for function argument direction configuration.

* std.cfg: runastyle and add some more direction configurations.

* library.h: Add documentation for function argument direction enum.

* Do not use "direction" library information for pointer arguments.

Also fix further unmatched uninitvar messages in std configuration
tests.

* std.cfg: Add more argument direction configurations.

* test/cfg/std.c: Add test for argument direction configuration.

* astutils.cpp: Only ignore pointer arguments for out/inout arguments.

* library.h: Use suggested documentation for argument direction enum.
2019-03-04 22:57:40 +01:00
Daniel Marjamäki 5087f15035 Travis: Try to fix 'make checkcfg' 2019-03-02 19:38:11 +01:00
Daniel Marjamäki e6e3987935 snprintf/g_snprintf: do not allow uninitialized target buffer 2018-12-22 20:40:47 +01:00
Daniel Marjamäki 9742c1e2ae make checkcfg: Try to fix inline suppressions 2018-12-14 13:51:03 +01:00
Daniel Marjamäki 0b4e08cac9 Use FwdAnalysis in UnusedVar. This is still work-in-progress. Merging to master branch so it can be tested. 2018-12-13 18:52:56 +01:00
Daniel Marjamäki ec89c7b1b8 Travis: redundantCopy is not detected at the moment 2018-11-24 11:27:27 +01:00
orbitcowboy 58b3d75b62 std.cfg: Added invalidFunctionArg cfg for strchr(). 2018-11-20 08:32:54 +01:00
rikardfalkeborn 613dc19b68 #4241: Check for address of single character passed as string (#1381)
* #4241: Check for address of single character passed as string

Add a check that address of a single character is not passed as argument
to argument marked as strings (using strz). The check does not warn if
the address of a character with known value '\0'.

Since ValueFlow currently does not handle global constants (see #7597),
do not warn if the variable is global to avoid FPs when the address of
a global variable assigned to '\0' is passed to a function expecting a
string.

Remove comment in docs saying strz is unused.

* Change asdf to Hello world

* Add test of address to first element in string

* Add error reporting function to getErrorMessages

* Fix strings in test
2018-10-14 18:49:34 +02:00
orbitcowboy 55ff7c0823 test std.cfg: Updated tests for strncpy_s(). 2018-05-31 11:23:54 +02:00