Commit Graph

421 Commits

Author SHA1 Message Date
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
amai2012 b5ee9d97ef Move some signal constants from posix.cfg to std.cfg. Add some more interfaces to posix.cfg 2019-04-26 19:26:04 +02:00
Daniel Marjamäki 87a3d2caa1 std.cfg: Add auto_ptr and weak_ptr configs 2019-04-24 14:21:26 +02:00
Daniel Marjamäki 2513c1499b Library: Added <smart-pointer> element 2019-04-24 13:06:58 +02:00
orbitcowboy 7ac3bf5fd8 std.cfg: Removed MIN/MAX macros since they cause problems with http://cppcheck.osuosl.org:8000/amap-align 2019-04-03 09:11:48 +02:00
Daniel Marjamäki b88cc7c19d Fix std.cfg 2019-04-01 20:28:31 +02:00
Daniel Marjamäki 761f18c75c Fixed #8988 (False positive: using memset on struct) 2019-04-01 19:32:03 +02:00
versat 316475f79f std.cfg: Add "buffer-size" attribute and tests for aligned_alloc(). 2019-03-21 09:25:42 +01:00
Sebastian 432c04281a
Libraries: Move valloc() from std.cfg to posix.cfg. (#1743)
Move valloc() to posix.cfg since it is a legacy POSIX function and not
part of the standard (not even commonly used). It is not available in
msvc (Visual Studio).
2019-03-20 14:10:36 +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
Daniel Marjamäki 18668a52b9 Library: Added buffer-size attribute for <alloc> 2019-03-17 10:55:15 +01:00
orbitcowboy f449e75214 std.cfg: Added support for std::getline(). 2019-03-11 15:32:15 +01:00
Sebastian 0bab9d778b
std.cfg: Fix wprintf(), add comment to swprintf(). (#1729)
wprintf(): The format string must be initialized. So add `<not-uninit/>`
swprintf(): `<formatstr/>` should not be used because Microsoft uses the
same function with a different order of the arguments. Add comment to
document this in the library configuration also. See ticket
https://trac.cppcheck.net/ticket/4790
2019-03-06 21:13:48 +01:00
orbitcowboy 8c0ab16863 std.cfg: Added support for more interfaces. 2019-03-05 18:13:42 +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
versat 0ae24b950f std.cfg: Add support for snprintf_s().
sprintf_s works very similar but it is already configured in the
windows library. Configuring sprintf_s in std.cfg leads to conflicts in
the windows configuration tests.
Found by daca@home
2019-03-05 14:44:33 +01:00
versat ce818631ab std.cfg: Add support for ctime_s(). 2019-03-05 13:57:52 +01:00
Sebastian 9efb720a98
std.cfg: Add missing argument directions as far as possible. (#1725)
I added all argument directions i know or where i was able to find
information without too much effort. When in doubt i looked at the
Microsoft SAL annotations and used similar configurations when this
made sense.
2019-03-05 13:45:41 +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
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
orbitcowboy aa4265978c std.cfg: Added support for std::list::remove(). 2019-03-01 15:10:36 +01:00
orbitcowboy 16e3a0ada6 std.cfg: Added support for std::shuffle() and std::random_shuffle(). 2019-03-01 15:05:10 +01:00
orbitcowboy 9348a627e0 std.cfg: Added support for more interfaces. 2019-03-01 09:28:46 +01:00
orbitcowboy 2fad53e4f8 std.cfg: Enusre the return value of realloc()-functions is taken into account. 2019-03-01 08:57:59 +01:00
orbitcowboy f70e01b2b1 std.cfg: Added (experimental) support for MIN/MAX-macros. In case it turnes out this causes unexpected side effects, they can be easily removed. 2019-02-28 23:03:38 +01:00
Sebastian 71b1b2dd76
std.cfg: Add support for std::vector::assign(). (#1713)
Reference:
https://en.cppreference.com/w/cpp/container/vector/assign
2019-02-28 18:43:54 +01:00
Sebastian 13b37631a6
std.cfg: Add support for std::vector::swap() and std::swap() (#1700)
References:
https://en.cppreference.com/w/cpp/container/vector/swap
https://en.cppreference.com/w/cpp/algorithm/swap
2019-02-26 18:21:17 +01:00
orbitcowboy d218fa5919 std.cfg: Added support for more interfaces. 2019-02-24 18:43:07 +01:00
orbitcowboy 406b29548a std.cfg: Added support for more interfaces. 2019-02-24 18:35:02 +01:00
orbitcowboy 32e1d383a4 std.cfg: Added support for std::replace() and std::replace_if(). 2019-02-24 00:06:38 +01:00
orbitcowboy 748fe7f25e std.cfg: Added support for std::back_inserter(). 2019-02-24 00:00:20 +01:00
orbitcowboy c38cbd967b std.cfg: Added support for std::reverse(). 2019-02-23 23:55:13 +01:00
orbitcowboy 59d3ce2343 std.cfg: Added support for std::remove_if(). 2019-02-23 23:51:11 +01:00
orbitcowboy 568887eadf std.cfg: Added support for std::unique(). 2019-02-23 23:44:23 +01:00
orbitcowboy 0fa70ebb2a std.cfg: Added support for more interfaces. 2019-02-23 18:38:48 +01:00
orbitcowboy 216d324a59 std.cfg: Added support for more interfaces. 2019-02-23 18:35:13 +01:00
orbitcowboy af9cbe23f9 std.cfg: Added support for more interfaces. 2019-02-20 10:02:01 +01:00
orbitcowboy a7b9d8de1b std.cfg: Added support for std::ios_base::setf() and std::ostringstream::setf(). 2019-02-18 12:20:34 +01:00
orbitcowboy 5135cbeecd std.cfg: Added support for std::multiset::insert(). 2019-02-17 23:15:46 +01:00
orbitcowboy 3aa131470b std.cfg: Added support for std::vector::erase(). 2019-02-17 23:10:17 +01:00
orbitcowboy af4f3af851 std.cfg: Added support for std::fill(). 2019-02-17 22:58:30 +01:00
orbitcowboy c28abe7e35 std.cfg: Added support for std::map::insert(). 2019-02-17 22:50:18 +01:00
orbitcowboy 1df9c80e81 std.cfg: Added support for std::move(). 2019-02-17 22:45:45 +01:00
orbitcowboy 7629923b65 std.cfg: Attempt make travis happy. 2019-02-16 08:24:53 +01:00
orbitcowboy 437e171d0d std.cfg: Added partial support for std::transform(). 2019-02-15 20:56:44 +01:00
orbitcowboy 23b771c5c8 std.cfg: Added partial support for std::sort(). 2019-02-15 20:45:46 +01:00
orbitcowboy 103ec5b5a1 std.cfg: Added support for std::wifstream::seekg(). 2019-02-13 08:52:45 +01:00
orbitcowboy 81dab88413 std.cfg: Fixed wrong configuration from std::vector::pop_back(). 2019-02-13 08:04:11 +01:00
orbitcowboy 40398c6c90 std.cfg: Added support for std::vector::pop_back() and std::vector::push_back (). 2019-02-12 18:52:18 +01:00
Sebastian d9241aa532
std.cfg: Add support for std::string::replace() (#1661)
Reference: https://en.cppreference.com/w/cpp/string/basic_string/replace
2019-02-11 16:06:48 +01:00