Commit Graph

940 Commits

Author SHA1 Message Date
Sebastian c990d10ffa
Check for JSON error when parsing addon .json files + fixes (#2374)
* cppcheck.cpp: Check for JSON error when parsing addon .json files

This fixes that errors in JSON files given via `--addon=*.json` are
silently ignored and maybe only a part of the JSON file is used.
Now the error message which picojson can return is checked and a
corresponding error message is returned again by getAddonInfo().

* naming.json: Fix missing comma

* CLI: Fix naming violations detected by addon naming.py via naming.json

* Addon naming: Add argument for validating names of constants

* LIB: Rename functions/variables so they are valid, loosen naming rules

* GUI: Fix naming violations
2019-11-20 15:37:09 +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 c75bbbe253 Fix issue 9404: False positive: Either the condition 'if(x)' is redundant or there is possible null pointer dereference: a->x (#2322)
* Fix issue 9404: False positive: Either the condition 'if(x)' is redundant or there is possible null pointer dereference: a->x

* Use simpleMatch

* Add a test case for the FP

* Check if expression is changed

* Check for no return scope

* Use simpleMatch
2019-11-08 08:11:41 +01:00
Daniel Marjamäki c7a23f126f Fixed #9373 (False Positive - missingOverride) 2019-11-03 18:42:04 +01:00
Daniel Marjamäki 6d1c84e3a6 Fixed #9449 (SymbolDatabase: Function lookup fails when string literal is converted to bool) 2019-10-30 21:05:42 +01:00
IOBYTE 6b4a3bc830 fix #9431 (Invalid syntax error on valid C++ code) (#2298) 2019-10-26 17:39:46 +02:00
Georgy Komarov 72f07c8a33 Add MISRA checks for rules 21.1 and 21.12 (#2284)
* Add MISRA 21.1 check

This also required add static field for functions in symboldatabase.

* Add MISRA R21.12

* Use newer ASSERT macroses in tests
2019-10-26 08:32:46 +02:00
Daniel Marjamäki dedee2b173 SymbolDatabase: Better ValueType handling for containers 2019-10-23 19:54:59 +02:00
Daniel Marjamäki 87f65230ae SymbolDatabase: Better valuetype handling of container addition 2019-10-23 12:42:46 +02:00
Daniel Marjamäki f131a99ae3 SymbolDatabase: Improved ValueType in range for loop 2019-10-23 11:52:29 +02:00
Daniel Marjamäki c5c07b61a6 SymbolDatabase: Fix type for expression 'x = uint8_t(a[b])' 2019-10-22 20:40:36 +02:00
Daniel Marjamäki 223ceeb97f SymbolDatabase: Do not set constructor flag for function in namespace 2019-10-20 18:12:52 +02:00
Daniel Marjamäki 82d8f3e7f5 SymbolDatabase: Fix crash if std::shared_ptr type is only forwarded, not defined 2019-10-20 17:00:15 +02:00
Rikard Falkeborn 5c061c1c12 Set correct type and size of string and char literals (#2275)
* Set correct type and size of string and char literals

Use that string and char literal tokens store the prefix. This makes
it possible to distinghuish between different type of string literals
(i.e., utf8 encoded strings, utf16, wide strings, etc) which have
different type.

When the tokens holding the string and character values have the correct
type, it is possible to improve Token::getStrSize() to give the correct
result for all string types. Previously, it would return the number of
characters in the string, i.e., it would give the wrong size unless
the type of the string was char*.

Since strings now can have different size (in number of bytes) and
length (in number of elements), add a new helper function that returns
the number of characters. Checkers have been updated to use the correct
functions.

Having the size makes it possible to find more problems with prefixed
strings, and to reduce false positives, for example in the buffer
overflow checker.

Also, improve the stringLiteralWrite error message to also print the
prefix of the string (if there is one).

* Add comment and update string length
2019-10-20 07:11:57 +02:00
IOBYTE 5658dfcaf3 better fix for #9392 that also handles namespaces (#2282) 2019-10-18 18:05:48 +02:00
Daniel Marjamäki 7d6d561c84 SymbolDatabase: Better handling of function call using smart pointer 2019-10-15 19:33:25 +02:00
Daniel Marjamäki 4a4b4963cc SymbolDatabase: Fix function lookup for '::func()' 2019-10-15 12:39:02 +02:00
Daniel Marjamäki bf61bcf402 ValueType: Set ValueType for constructor calls 2019-10-14 09:19:16 +02:00
Paul Fultz II 19cf636a4a Move necessary code into valuetype (#2265)
* Fix parsing of smart pointers

* Improve deduction of return type

* Valuetype computation for decayed pointers
2019-10-12 11:40:02 +02:00
IOBYTE f99e83ece0 Fix #9411 (new daca crash related to using namespace) (#2264) 2019-10-12 11:39:14 +02:00
IOBYTE fe1f601b91 Fix #9389 ("debug: Executable scope 'x' with unknown function." with … (#2261)
* Fix #9389 ("debug: Executable scope 'x' with unknown function." with "using namespace")

* use static rather than anonymous namespace for new functions
2019-10-10 20:25:09 +02:00
orbitcowboy a9386fa093 Running astyle [ci skip] 2019-10-10 08:17:41 +02:00
Daniel Marjamäki 0c1e979af7 SymbolDatabase: Refactor handling of variable declarations in if condition 2019-10-09 22:27:48 +02:00
Daniel Marjamäki 9f4db5018d SymbolDatabase: Added testcase for variable in if-scope 2019-10-09 16:41:07 +02:00
Daniel Marjamäki 3776604f06 SymbolDatabase: Add variable in if condition 'if (auto x = bar())' 2019-10-09 15:55:54 +02:00
Daniel Marjamäki 1abf70a7cb SymbolDatabase: Add null pointer check for ast operand for '(' token 2019-10-08 17:53:29 +02:00
Daniel Marjamäki 9f40341ba8 SymbolDatabase: Hardcoded handling for std::make_shared and std::make_unique , todo: library configuration would be better than hard coding 2019-10-08 17:19:24 +02:00
Daniel Marjamäki 79356b1883 SymbolDatabase: Better ValueType handling of 'LibraryType(..)' 2019-10-08 11:25:05 +02:00
Paul Fultz II 4eb4762d95 Extend lifetime checking to temporaries (#2242)
* Use lifetimes to check for returning reference to temporaries

* Check for dangling temporaries

* Check for unknown types for returining by reference

* Remove old returnTemporary check

* Format

* Check for deref op

* Ternary operator return an lvalue reference

* Warn when returning temporaries from member functions

* Improve handling of pointer to function

* Extend lifetimes of const references
2019-10-08 09:28:39 +02:00
Daniel Marjamäki 3c085fd88a Fixed #9359 (SymbolDatabase: function lookup fails when -funsigned-char is used) 2019-10-06 12:05:58 +02:00
IOBYTE 8f46bb3ef6 fix #9392 (SymbolDatabase: Weird default constructor outside class) (#2243) 2019-10-06 07:21:12 +02:00
Daniel Marjamäki 7294145797 SymbolDatabase: set value type for std::move() 2019-10-05 19:57:52 +02:00
Daniel Marjamäki cf965b72b5 SymbolDatabase: look for functions in anonymous namespaces in the findFunction 2019-10-01 19:09:34 +02:00
Paul Fultz II 166bd2bafc Fix issue 2153: valueFlowAfterCondition: struct member (#2228)
* Fix issue 2153: valueFlowAfterCondition: struct member

* Fix null pointer dereference

* Formatting

* Check for another null pointer

* Initialize variables

* Remove redundant condition

* Format

* Add missing initialization to copy constructor

* Format
2019-09-30 21:04:43 +02: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 4138bf7fb3 SymbolDatabase: Better handling when return type of function is PodType 2019-09-28 14:57:41 +02:00
Oliver Stöneberg eac040a00b Various clang-tidy fixes (#2192)
* use range loops

* removed redundant string initializations

* use nullptr

* use proper boolean false

* removed unnecessary continue from end of loop

* removed unnecessary c_str() usage

* use emplace_back()

* removed redundant void arguments
2019-09-25 15:25:19 +02:00
Oliver Stöneberg de9f489b08 use range loops / constness (#2181)
* use range loops / constness

* platform.cpp: avoid shadowed variable
2019-09-19 20:29:33 +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
IOBYTE e5220bdf0c make ellipsis ... a single token (#2143)
* make ellipsis ... a single token

Using cppcheck -E to preprocess code with ellipsis produces output that
can't be compiled because ... is split into 3 tokens.

* try to fix addon
2019-09-04 08:07:30 +02:00
Ken-Patrick 2c656d6586 Issue 9255: Prevent infinite recursion in parsedecl (#2134) 2019-09-01 11:36:02 +02:00
Ken-Patrick d1c6cb9aa5 Fix issue 9304: boolean type of ternary (#2131)
* Add test cases for 9304

* Fix 9304
2019-09-01 09:51:53 +02:00
Paul Fultz II bd02ca5ccb Fix issue 9207: Not detected 'always true' and unreachable code 2019-08-08 07:46:47 +02:00
Daniel Marjamäki ebcca4edd1 Improve --debug-warnings output for 'auto' tokens without type. Do not report that prematurely before the type is set properly. 2019-08-05 13:42:06 +02:00
Paul Fultz II ffdd2dc793 Fix issue 8924: Re-enable valueFlowTerminatingCondition 2019-08-05 07:18:06 +02:00
Daniel Marjamäki c03df8e6b4 SymbolDatabase: Improved matchParameter for containers 2019-08-03 10:10:40 +02:00
amai2012 f02636e995 Refactoring: Convert enums to enum classes 2019-08-02 21:14:29 +02:00
Daniel Marjamäki e66e6549ee SymbolDatabase: Improved ValueType::matchParameter handling of containers 2019-08-02 15:59:22 +02:00
Daniel Marjamäki 26b0ea52ed SymbolDatabase: Simplify code 2019-08-02 15:41:18 +02:00
Daniel Marjamäki 7eaa49fd5b Refactoring SymbolDatabase::findFunction. No functional change is intended. 2019-08-01 17:53:14 +02:00