Commit Graph

487 Commits

Author SHA1 Message Date
Daniel Marjamäki beea7fa8d2 Token::index(): Created Token member that indicates the Token position in the token list. It can be used to quickly check if tok1 precedes tok2. 2019-06-21 22:16:23 +02:00
orbitcowboy 821903e2e1 Running astyle [ci skip] 2019-06-02 13:29:20 +02:00
Paul Fultz II 6ae7be0f53 Fix FP with lifetime containers (#1865) 2019-06-02 10:14:48 +02:00
adamjrichter 47ce998e6e lib: Separate statements of the form "assert(a && b)" into "assert(a)" and "assert(b)", for more precise diagnostics. (#1825) 2019-05-07 10:28:31 +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
Rikard Falkeborn c7d7f8738c Optimize astStringVerbose() for large arrays (#1815)
Change the astStringVerbose() recursion to extend a string instead of
returning one. This has the benefit that for tokens where the recursion
runs deep (typically large arrays), the time savings can be substantial
(see comments on benchmarks further down).

The reason is that previously, for each token, the astString of its
operands was constructed, and then appended to this tokens astString.
This led to a lot of unnecessary string copying (and with that
allocations). Instead, by passing the string by reference, the number
of temporary strings is greatly reduced.

Another way of seeing it is that previously, the string was constructed
from end to beginning, but now it is constructed from the beginning to
end. There was no notable speedup by preallocating the entire string
using string::reserve() (at least not on Linux).

To benchmark, the changes and master were tested on Linux using the
commands:

	make
	time cppcheck --debug --verbose $file >/dev/null

i.e., the cppcheck binary was compiled with the settings in the
Makefile. Printing the output to screen or file will of course take
longer time.

In Trac ticket #8355 which triggered this change, an example file from the
Wine repository was attached. Running the above cppcheck on master took
24 minutes and with the changes in this commmit, took 22 seconds.

Another test made was on lib/tokenlist.cpp in the cppcheck repo, which is
more "normal" file. On that file there was no measurable time difference.

A synthetic benchmark was generated to illustrate the effects on dumping
the ast for arrays of different sizes. The generate code looked as
follows:

	const int array[] = {...};

with different number of elements. The results are as follows (times are
in seconds):

	N	master optimized
	10	0.1    0.1
	100	0.1    0.1
	1000	2.8    0.7
	2000	19     1.8
	3000	53     3.8
	5000	350    10
	10000	3215   38

As we can see, for small arrays, there is no time difference, but for
large arrays the time savings are substantial.
2019-04-30 13:35:48 +02:00
Daniel Marjamäki b1b5b27b4e addons: write column in error message(s) 2019-04-13 10:22:13 +02:00
Rikard Falkeborn 794f65bac1 Handle prefixed strings and characters in Token (#1742)
This makes it possible to call getStrLength() and similar functions
before the tokenizer is called.
2019-03-18 06:18:25 +01:00
Daniel Marjamäki 92f4113b59 Array index: Checking array index out of bounds for dynamic buffers 2019-03-17 13:09:15 +01:00
Daniel Marjamäki df8cfe2fc6 Travis: Fix Cppcheck warning 2019-03-10 12:24:41 +01:00
Rikard Falkeborn 6a3dd9a185 Handle concatenated string and char literals
This handles concatenated strings and characters from simplecpp.
Previously, L'c' would be preprocessed to the tokens  "L" and "'c'".
cppcheck would then remove the "L" token and set "'c'" to be a wide
character literal. Now, it needs to remove the prefix instead.

When doing this, add handling of utf32 encoded literals (U) and UTF-8
encoded literals (u8).
2019-03-10 10:38:50 +01:00
Daniel Marjamäki bd7790fd8c Update copyright year 2019-02-09 07:24:06 +01:00
Daniel Marjamäki a26287f491 Fix Token::findExpressionStartEndTokens() regression 2019-01-20 13:23:19 +01:00
Daniel Marjamäki 8da4e31c42 Fixed #8941 (False Positive: Variable 'f' is assigned a value that is never used.) 2019-01-20 13:20:23 +01:00
Daniel Marjamäki b97b3b7ef8 astyle formatting
[ci skip]
2018-12-21 13:54:59 +01:00
rebnridgway 431d068339 Several fairly significant optimisations (#1518)
* Code changes for Token::mImpl optimisation

* Added new TokenImpl optimisation

Moving members to the TokenImpl struct reduces the size of the Token class, which is a fairly significant optimisation.  In my testing on Windows with 32-bit Release-PCRE, this change reduced the size of the Token class from 108 bits to 52 bits and reduced run-time of my test case by around 20%.

* Several optimisations

Deleted some code that ran very slowly and did nothing, as there is no need to change a Token's string to null if you are about to delete it.
Added a frontToken to simplifyCalculations to reduce the amount of work it has to do on already-simplified calculations.
Moved template removal to the end of the list as this reduces redundant iteration and saves time.

* Added tok argument to simplifyCalculations

This means callers can avoid unnecessary work if they know which tokens have already been simplified.  Passing nullptr indicates the original behaviour (starting from the front of the list).

* Removed mention of member from another change

* Re-added and optimised some code deleted in error

Changing mTemplateInstantiations to a vector avoids the high cost of doing repeated linear searches.  Changing how the code iterates through the array was necessary because the vector can be resized at several points during the loop, which breaks existing references and iterators.

* Changed mTemplateInstantiations to a vector

This is an optimisation that makes repeated linear searches of this collection significantly faster. 
Also added a copy constructor to TokenAndName so code can make copies of these objects to keep a reference if a vector gets resized.

* A cleaner optimisation to removing template tokens

This reverts the previous change to made mInstantiatedTemplates a vector and the iterator changes to support this, and makes mTypesUsedInTemplateInstantiation so the eraseTokens logic can be unified.

* Reverted vector to list

Also made mTypesUsedInTemplateInstantiation a vector of TokenAndName objects so it can share the same logic as the other members.

* Added member for template simplifier pointer

This can be used more efficiently than marking Tokens with a flag and then searching through all templates to find the one that matches.

* Turned loop inside out

This means we only have to iterate through the std::list once.  std::list is very expensive to iterate through.

* Latest code from danmar and fixed optimisations

In particular I have optimised simplifying template instantiation names as this was incredibly slow because of the number of times it had to iterate through the template instantiation list.  Previous optimisations to this weren't very effective and broke some edge cases.

* Added changes from danmar

Made mExplicitInstantiationsToDelete a vector of TokenAndName to be consistent with the rest of the members, which are cleaned up very efficiently.

* Tokens can have many templateSimplifierPointers

* templateSimplifierPointers must be kept in sync
2018-12-21 13:51:45 +01:00
Daniel Marjamäki 37416010ef Unused value: Fix false positive (ast, {}) 2018-12-14 18:56:09 +01:00
Daniel Marjamäki 39c04b650d astyle formatting
[ci skip]
2018-11-14 19:10:52 +01:00
Paul Fultz II 54453c5802 Fix FP when copying pointer to string (#1479) 2018-11-14 06:59:25 +01:00
Paul Fultz II e839001f3d Fix warnings (#1478) 2018-11-14 06:14:04 +01:00
IOBYTE 17a8a4898d Fix another template simplifier namespace bug. (#1467)
* Fix another template simplifier namespace bug.

* Add missing forward declarations caused by token bug.
2018-11-07 21:25:42 +01:00
Daniel Marjamäki 58b21e3071 Refactoring: Reuse Token::expressionString() logic for finding right-most leaf in tree 2018-10-18 12:09:55 +02:00
IOBYTE 0a30768b59 Fixed #8693 (Template specialization: Constructor detected as normal … (#1418)
* Fixed #8693 (Template specialization: Constructor detected as normal function (functionStatic error))

Refactor template simplifier to remove the existing full specialization
function expandSpecialized and allow full specializations to use the
existing function expandTemplate.  The function expandTemplate was
modified to either expand the template like it originally did by copying
it or to modify the template in place.  Both instantiated and
uninstantiated full specializations are modified in place.  This also
fixes #8692 and probably other related tickets as well.

The function simplifyTemplates now tries twice to simplify templates so
more templates can be simplified.  We should try as many times as
necessary to find all possible templates.  We can't do that now because
uninstantiated templates are left unchanged.  It is relatively straight
forward to have the new code also expand in place uninstantiated
templates with their symbolic types but namespaces are not handled
properly (ticket #8671) and it would introduce regressions.

* Fix travis warnings.
2018-10-14 16:57:07 +02:00
Daniel Marjamäki 81f54f7094 Fixed #8681 (ValueFlow: Container size) 2018-08-10 11:29:16 +02:00
Paul Fultz II 0d35a96594 Improve checking of mismatch iterators (#1293) 2018-07-26 22:00:48 +02:00
Daniel Marjamäki 7c4820e047 Rename Library::isargvalid() 2018-07-15 23:05:48 +02: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
Daniel Marjamäki ad4ce84cf7 Rename private member variables 2018-06-17 17:20:16 +02:00
Daniel Marjamäki ac28ae5788 Renamed Token::_str 2018-06-16 23:03:15 +02:00
Daniel Marjamäki 237314fb51 Rename _values to mValues 2018-06-16 21:45:53 +02:00
Daniel Marjamäki 0452c5a4e4 Renamed _bits to mBits 2018-06-16 21:43:44 +02:00
Daniel Marjamäki d468eca772 Renamed _valuetype to mValueType 2018-06-16 21:42:40 +02:00
Daniel Marjamäki 82169b6247 Renamed _originalName to mOriginalName 2018-06-16 21:40:25 +02:00
Daniel Marjamäki 759097301b Rename _link to mLink 2018-06-16 20:30:09 +02:00
Daniel Marjamäki e8a00a38ac Rename _scope to mScope 2018-06-16 20:29:17 +02:00
Daniel Marjamäki 964841ba25 Rename _function to mFunction 2018-06-16 20:26:43 +02:00
Daniel Marjamäki 78974e9267 Rename _type to mType 2018-06-16 20:25:54 +02:00
Daniel Marjamäki 31f137f24d Renamed _fileIndex, _linenr, _col 2018-06-16 16:43:54 +02:00
Daniel Marjamäki a6e4663445 Renamed _progressValue to mProgressValue 2018-06-16 16:41:25 +02:00
Daniel Marjamäki aeea2e7427 Renamed _tokType to mTokType 2018-06-16 16:40:02 +02:00
Daniel Marjamäki 8e2b18a75a Rename _varId to mVarId 2018-06-16 16:38:50 +02:00
Daniel Marjamäki cc521bef99 renamed _tokensFrontBack to mTokensFrontBack 2018-06-16 16:22:35 +02:00
Daniel Marjamäki 26d58ddbb9 rename _astOperand1, _astOperand2, _astParent 2018-06-16 16:18:50 +02:00
Daniel Marjamäki 435aa70c3d rename _previous and _next 2018-06-16 16:16:55 +02:00
Daniel Marjamäki 363f4ca939 rename _flags to mFlags 2018-06-16 16:14:34 +02:00
amai2012 db7d267c02 Refactoring: Add _ prefix to Token member variables (#1280) 2018-06-09 08:14:24 +02:00
orbitcowboy de66eedd54 Improved const correctness of local variables. 2018-05-29 17:33:43 +02:00
rebnridgway 42a65c5160 Fix crash bug #8579 (#1238)
* Added declaration for deletePrevious function

* Added definition for deletePrevious function

* Fixed crash from deleteThis invalidating pointers

The crash was caused by deleteThis() invalidating the pointer to a constant variable usage.  This happened when a usage followed an assignment.  This fixes bug #8579.

* Added tokensFront to match tokensBack

This means deletePrevious can set the list's front if necessary.

* Initialised tokensFront in appropriate places

* Switched to using default Token constructor

* Switched to using Token default constructor

* Switched to using default constructor for Token

* Added missing argument to Token constructor

* Changed to use default constructor for Tokens

* Switched to using default constructor for Tokens

* Switched to using default constructor for Token

* Added new test for deleting front Token

Also made sure to use the correct constructor for Token in other tests.

* Syntax error

* Replaced tokensFront and tokensBack with a struct

This decreases the size of the Token class for performance purposes.

* Replaced tokensFront and tokensBack with a struct

* Added tokensFrontBack to destructor

* Reworked to use TokensBackFront struct

Also ran astyle.

* Reworked to use TokenList's TokensFrontBack member

* Reworked to use TokensFrontBack struct

* Reworked to use TokensFrontBack struct

* Reworked to work with TokensFrontBack struct

* Removed unnecessary scope operator

* Added missing parentheses

* Fixed syntax error

* Removed unnecessary constructor

* Default constructor now 0-initialises everything

This is safer for not using a temporary TokensFrontBack object, and doesn't use delegating constructors which aren't supported yet.

* Fixed unsafe null check

* Added missing explicit keyword

* Fixing stylistic nits

Removed default constructor as it has been superseded by the single-argument constructor with a default argument value.
Renamed listEnds to tokensFrontBack.
Fixed if statement that was supposed to be adding safety but would actually cause a crash if tokensFrontBack was null.

* Fixing stylistic nits

Removed default constructor and replaced it with a single-argument constructor with a default value.

* Fixing stylistic nits

Renamed _listEnds to _tokensFrontBack.

* Fixing stylistic nits

Renamed _listEnds to _tokensFrontBack.
2018-05-25 07:15:05 +02:00
Daniel Marjamäki 59cc479855 Save bitfield bit counts 2018-05-02 20:55:11 +02:00
Markus Elfring 521e3495b7 Adjustment for implementation of Token::insertToken() (#1194)
Three attributes are reset in this member function even if their values
are stored in the same token object.
Move a corresponding sanity check so that less assignments could be
performed eventually.
Link: https://trac.cppcheck.net/ticket/8532
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
2018-04-28 17:17:40 +02:00
PKEuS e2002db78d Replaced make_container by C++11 initializer lists 2018-04-08 23:03:44 +02:00
jrp2014 b6504c70ca Improve constness 2018-04-04 21:51:31 +02:00
Daniel Marjamäki 7e4dba6a7e Updated copyright year 2018-03-31 20:59:09 +02:00
Simon Martin 66d16b51f0 Ticket #8352: Properly detect AST cycles. (#1060) 2018-02-10 14:39:57 +01:00
orbitcowboy fb7f1efc49 token: Fixed potential null pointer dereference. (#1062) 2018-01-28 14:27:01 +01:00
Daniel Marjamäki c4caee6b18 Updated copyright year 2018-01-14 15:37:52 +01:00
Daniel Marjamäki 03b0b35a9d Refactor Token::findClosingBracket() 2018-01-01 12:22:04 +01:00
Daniel Marjamäki eaadfb3910 update debug token list output for templates. 2017-12-25 23:16:51 +01:00
Daniel Marjamäki b57dd4359b Fixed #8263 (check-library incorrectly reports missing configuration for case when value is in parentheses) 2017-11-17 22:10:39 +01:00
Florin Iucha cccf035535 Memoize token nature computation 2017-10-17 09:00:14 +02:00
Daniel Marjamäki ba8222de1c ValueFlow: Put 'inconclusive' state in the ValueKind. A value can't be both known and inconclusive. 2017-09-20 22:41:36 +02:00
Daniel Marjamäki 46c6620691 Token::takeData: dont keep old values or valuetype 2017-08-25 23:32:26 +02:00
Daniel Marjamäki ea0db18e0c Refactor Token::deleteThis() 2017-08-25 23:30:04 +02:00
Heiko Eißfeldt bab2b26d10 Fixed #8154 (heap use after free in tokenlist) 2017-08-25 17:17:19 +02:00
Daniel Marjamäki ca6109b40c threadsafety: Fix static data in Token::values() 2017-08-13 14:15:24 +02:00
Ayaz Salikhov b8cd7dbb5c Use nullptr instead of 0 or NULL (#936) 2017-08-09 20:00:26 +02:00
Daniel Marjamäki be998773ee Minor refactoring, fixes FP from Coverity 2017-08-01 11:33:24 +02:00
Daniel Marjamäki b41350e8d8 Token::expressionString(): Fixed output of library types 2017-07-22 16:42:42 +02:00
Daniel Marjamäki bf5040e3d6 Fixed #7701 (ValueFlow: handle 64-bit unsigned values ) 2017-07-22 12:19:46 +02:00
Daniel Marjamäki 12b7843937 astyle formatting
[ci skip]
2017-07-21 09:17:25 +02:00
Daniel Marjamäki 255d0410a4 Fixed #8085 (Token::expressionString: unsigned long long) 2017-07-21 09:16:42 +02:00
Ayaz Salikhov 28aa939d69 iwyu - include what you use 2017-05-27 04:33:47 +02:00
Daniel Marjamäki 6230919976 Skip 'Stringification => Tokenize' step 2017-05-17 14:57:54 +02:00
Daniel Marjamäki 7fd04cd8d0 Updated Token::expressionString(), write '->' instead of '.' 2017-04-30 14:22:18 +02:00
Daniel Marjamäki 8a738eefab fixed #7998 (uninitialized variable is not found when used with switch/case) 2017-04-23 18:05:14 +02:00
Daniel Marjamäki f8e9071de1 CheckFunction: In the <valid> check handle possible/conditional/inconclusive values better 2017-04-20 22:14:54 +02:00
PKEuS b1f4bd7504 Refactorization: Reimplemented Settings::_enabled as a bitfeld instead of std::set (#7995) 2017-04-11 11:49:26 +02:00
Matthias Krüger 79010eecea lib: fix a bunch of warnings about differing function arguments in definition and declaration.
[lib/token.h:72] -> [lib/token.cpp:36]: (style, inconclusive) Function 'Token' argument 1 names different: declaration 'tokensBack' definition 't'.
    [lib/token.h:445] -> [lib/token.cpp:497]: (style, inconclusive) Function 'multiCompare' argument 1 names different: declaration 'needle' definition 'tok'.
    [lib/checkio.h:73] -> [lib/checkio.cpp:1385]: (style, inconclusive) Function 'ArgumentInfo' argument 3 names different: declaration 'isCPP' definition '_isCPP'.
    [lib/checkother.h:216] -> [lib/checkother.cpp:2136]: (style, inconclusive) Function 'checkComparisonFunctionIsAlwaysTrueOrFalseError' argument 2 names different: declaration 'strFunctionName' definition 'functionName'.
    [lib/errorlogger.h:214] -> [lib/errorlogger.cpp:51]: (style, inconclusive) Function 'ErrorMessage' argument 2 names different: declaration 'file0' definition 'file0_'.
    [lib/errorlogger.h:215] -> [lib/errorlogger.cpp:65]: (style, inconclusive) Function 'ErrorMessage' argument 2 names different: declaration 'file0' definition 'file0_'.
    [lib/library.h:327] -> [lib/library.cpp:1043]: (style, inconclusive) Function 'ignorefunction' argument 1 names different: declaration 'function' definition 'functionName'.
    [lib/mathlib.h:112] -> [lib/mathlib.cpp:1275]: (style, inconclusive) Function 'isNullValue' argument 1 names different: declaration 'tok' definition 'str'.
    [lib/preprocessor.h:91] -> [lib/preprocessor.cpp:122]: (style, inconclusive) Function 'setDirectives' argument 1 names different: declaration 'tokens' definition 'tokens1'.
    [lib/symboldatabase.h:860] -> [lib/symboldatabase.cpp:1801]: (style, inconclusive) Function 'argsMatch' argument 1 names different: declaration 'info' definition 'scope'.
    [lib/symboldatabase.h:1171] -> [lib/symboldatabase.cpp:2048]: (style, inconclusive) Function 'addClassFunction' argument 1 names different: declaration 'info' definition 'scope'.
    [lib/symboldatabase.h:1174] -> [lib/symboldatabase.cpp:2208]: (style, inconclusive) Function 'addNewFunction' argument 1 names different: declaration 'info' definition 'scope'.
    [lib/symboldatabase.h:1090] -> [lib/symboldatabase.cpp:3648]: (style, inconclusive) Function 'findVariableType' argument 2 names different: declaration 'type' definition 'typeTok'.
    [lib/symboldatabase.h:1101] -> [lib/symboldatabase.cpp:4308]: (style, inconclusive) Function 'findType' argument 1 names different: declaration 'tok' definition 'startTok'.
    [lib/symboldatabase.h:1176] -> [lib/symboldatabase.cpp:4349]: (style, inconclusive) Function 'findTypeInNested' argument 1 names different: declaration 'tok' definition 'startTok'.
    [lib/symboldatabase.h:1193] -> [lib/symboldatabase.cpp:4501]: (style, inconclusive) Function 'setValueType' argument 2 names different: declaration 'enumerators' definition 'enumerator'.
    [lib/path.h:159] -> [lib/path.cpp:247]: (style, inconclusive) Function 'isCPP' argument 1 names different: declaration 'extensionInLowerCase' definition 'path'.
    [lib/path.h:145] -> [lib/path.cpp:266]: (style, inconclusive) Function 'acceptFile' argument 1 names different: declaration 'filename' definition 'path'.
2017-04-03 00:06:46 +02:00
Daniel Marjamäki 1faca91c1d Added 'endsWith' utility function. This will make compiling the democlient easier. 2017-04-01 18:14:18 +02:00
PKEuS 3c8f5b85ae Refactorization: Allocate Token::_values (ValueFlow information) dynamically, reducing size of each token by around 10% 2017-03-27 18:48:34 +02:00
Daniel Marjamäki 2f2ac46243 Replaced hardcoding for char16_t and char32_t with configuration 2017-03-04 16:30:42 +01:00
Daniel Marjamäki ecc59859e1 Don't simplify _Bool in TokenList 2017-03-04 11:13:28 +01:00
Frank Zingsheim c8ff96fe8f Fixed #6180 (Usage of variable after std::move or std::forward) 2016-11-20 15:14:49 +01:00
Daniel Marjamäki e1e9eacccc ValueFlow: Added float type 2016-11-13 22:59:56 +01:00
Daniel Marjamäki 4732667488 ValueFlow: allow more value types 2016-11-13 22:33:39 +01:00
orbitcowboy 960a0c6b11 Token: Improved const correctness of findsimplematch() and findmatch(). There are no functional changes. 2016-10-29 21:37:45 +02:00
Boris Egorov 0154d39bf6 Show struct member in unsignedLessThanZeroError warning
Before:
    [/tmp/test.c:8]: (style) Checking if unsigned variable '.' is less than zero.
    [/tmp/test.c:12]: (style) Checking if unsigned variable '.' is less than zero.

After:
    [/tmp/test.c:8]: (style) Checking if unsigned variable 'd.n' is less than zero.
    [/tmp/test.c:12]: (style) Checking if unsigned variable 'd.n' is less than zero.
2016-09-22 08:03:30 +07:00
Daniel Marjamäki a65ae3ce2e Token: Allow dollar sign in identifiers 2016-07-29 13:42:11 +02:00
Daniel Marjamäki b9443771fb cleanup tests 2016-07-18 10:42:03 +02:00
Daniel Marjamäki dc2a92263a Fixed #7426 (RFC: time to replace simplifyEnum?) 2016-04-22 06:02:54 +02:00
PKEuS b801386ac8 Fixed bug in Token::findClosingBracket() and broken unit test (#7277) 2016-02-04 10:00:54 +01:00
PKEuS e063e97831 Fixed bug in Token::swapWithNext(): swap _link correctly 2016-02-02 17:47:36 +01:00
PKEuS d8b75e3492 Fixed several bugs when deleting and swapping tokens 2016-02-02 17:30:14 +01:00
PKEuS 4b9241f643 Removed support for patterns like |a|b and a||b (equal to a|b|)
-> Improved performance by 1,3% (non-matchcompiled build)
2016-02-02 11:46:42 +01:00
Daniel Marjamäki 95009a4630 Merge pull request #745 from lanurmi/2016_ad
Update copyright year to 2007-2016.
2016-01-01 22:57:19 +01:00
Lauri Nurmi 996c9244d8 Update copyright year to 2007-2016. 2016-01-01 15:34:45 +02:00
Daniel Marjamäki 1e0979779e Print type information in AST dump 2016-01-01 13:54:07 +01:00
Daniel Marjamäki 8171154e12 Fixed #7230 (Confusing code snippet in error message) 2015-12-31 01:15:49 +01:00
Daniel Marjamäki 81f0597316 Fixed #3206 and #7226 (New check: Undefined execution order) 2015-12-24 09:13:20 +01:00
PKEuS 18693a7fce Refactorized token.cpp:
- Removed redundant overload of Token::insertToken()
- Fixed leak in Token::deleteThis()
- Moved condition out of loop in Token::tokAt()
2015-12-14 22:04:51 +01:00
Alexander Mai 9d8dffbd79 #6269 false positives in case of overloaded standard library functions. Detect memset() with proper argument cound, using new function numberOfArguments() 2015-12-06 12:50:05 +01:00
Alexander Mai e69377d5a8 #7183 CheckClass::checkMemset() uint overflow. Plus some minor refactoring 2015-12-05 18:22:01 +01:00
PKEuS e8522c7883 Small refactorizations:
- #include cleanup
- Use std::array instead of std::vector
- Do not create a stringstream to concatenate 4 strings
- Use std::cout instead of printf
2015-11-29 10:56:44 +01:00
Daniel Marjamäki 0f9d90d2be Changed Copyrights. Removed my name. 2015-11-18 20:04:50 +01:00
PKEuS 636bf75799 Fixed crash on garbage code (#7074) 2015-10-26 13:29:47 +01:00
PKEuS 0370c66e41 Fixed broken function Token::getCharAt() (#7073) 2015-10-26 11:51:05 +01:00
Philipp Kloke a837cc48e0 Refactorization: Simplified code in tokenlist.cpp, token.cpp and testthreadexecutor.cpp 2015-10-19 09:01:20 +02:00
Daniel Marjamäki 40fffddb83 avoid some fixes for noisy signedness warnings 2015-10-11 12:36:23 +02:00
PKEuS 50ed47c725 Fixed crash on garbage code (#7022) 2015-10-07 13:52:06 +02:00
Daniel Marjamäki 9b253612ca SymbolDatabase: Add type information in AST 2015-10-04 19:42:58 +02:00
PKEuS fbbdfa85ca Revert "Fixed false negative #5815"
This reverts commit dc6c278d83.
2015-09-09 14:46:47 +02:00
PKEuS dc6c278d83 Fixed false negative #5815 2015-08-31 14:12:19 +02:00
Daniel Marjamäki 436d7b6d59 Merge pull request #655 from Dmitry-Me/explicitConstCastBetterNames
Use const_cast to add const, better variable name
2015-08-27 17:04:07 +02:00
Dmitry-Me c760ccee13 Use const_cast to add const, better variable name 2015-08-27 17:14:33 +03:00
PKEuS 2ace3d3144 Rewritten handling of declaration specifiers:
- Removed simplifyConst() because it did the opposite of the (superior) simplifyStaticConst()
- Execute simplifyStaticConst() in simplifyTokenList1() - there is no reason to defer it, and it is required to properly parse declarations like "unsigned static int i;"
- Fixed simplifyStaticConst() to handle more patterns. It did not work at the beginning of the token list and for function arguments
- Reimplemented Tokenizer::simplifyStdType()
-> properly support all possible ways to declare integers as requested by the standard, instead of only a few common permutations of "unsigned|signed", "short|char|long|int"
-> Fixed parsing of _Complex/complex types
2015-08-27 14:34:17 +02:00
PKEuS 4d80df2f4a Added pointer to Type to Token (similar to Token::Variable() and Token::function()):
- Accessible via Token::type()
- Renamed former Token::type() to Token::tokType()
- Removed SymbolDatabase::isClassOrStruct()
2015-08-15 11:19:21 +02:00
Daniel Marjamäki 6865724c4e Fixed #6914 (Token::expressionString: parenthesis missing in expression (*it)->stats.corpse_ticks) 2015-08-12 10:55:25 +02:00
Daniel Marjamäki e598b07a6d Moved functions to astutils 2015-08-03 09:20:50 +02:00
Daniel Marjamäki 251f6d2a15 Fixed #6898 (Token::expressionString: wrong output when first token is post-incremented) 2015-07-31 07:03:52 +02:00
Daniel Marjamäki ae124cb365 ValueFlow: Attempt to make --debug output easier to understand by using words 2015-07-26 16:32:31 +02:00
Daniel Marjamäki 9197e70a8d ValueFlow: Changed --debug output so we can see if a variable is known or possible 2015-07-26 15:36:09 +02:00
PKEuS 8ed0180279 Use C++11 string.back() instead of string[string.length()-1] 2015-07-25 17:19:53 +02:00
Daniel Marjamäki e5151a13ab Fixed #6867 (False positive memleak) 2015-07-25 11:37:03 +02:00
Daniel Marjamäki b2b4bb49fa Refactoring handling of comparisons 2015-07-22 12:31:18 +02:00
Daniel Marjamäki 2e2735518e AST: Updated printAst 2015-07-21 11:54:11 +02:00
Alexander Mai b604d63dd8 #6726 cppcheck hangs with 100% CPU load (invalidcode) inside Token::astOperand2(). #6840 egmentation fault (invalid code) in Token::astOperand2. Improve stability on invalid code 2015-07-15 15:19:48 +02:00
Alexander Mai b30d9ffe98 #6838 cppcheck hangs on some strange input code. Token::astOperand1/2 throw internal error on garbage code instead of creating endless recursion in AST 2015-07-14 21:07:10 +02:00
Alexander Mai 6e03e7dca2 Remove some code checking for invalid class hierarchy which got obsolete since 480a5672b0. Run astyle 2015-07-01 07:50:13 +02:00
amai2012 99dfd55d0c #6804 segmentation fault (invalid code) in Token::getValueTokenDeadPointer. Fix null pointer access
TestGarbage: Increase coverage by running all code snippets as C as well as C++ code. (inspired by #6800)
2015-06-30 19:40:22 +02:00
amai2012 c0b91662ba #6803 segmentation fault (invalid code) in Token::findClosingBracket. 2015-06-30 12:16:55 +02:00
Alexander Mai d704e97203 Fix (potential) multi-threading issues by moving static local vars (non-POD-type) to file scope 2015-06-10 21:14:17 +02:00
Dmitry-Me cae605b1ec New warning: warn about redundant code in condition. 2015-06-10 18:53:55 +02:00
Daniel Marjamäki 75b0430ba5 Token::strValue: fixed handling of backslash 2015-06-07 11:25:33 +02:00
Daniel Marjamäki eb0db322eb Fixed #6560 (ValueFlow: handling ternary operator better in valueFlowSubFunction) 2015-05-24 17:02:00 +02:00
Alexander Mai 394160184a Refactoring: Replace complex if/else cascade by search in a container. Remove redundant plain arrays (in favour of container) 2015-05-24 09:43:17 +02:00
PKEuS d5ad1def40 Removed two unused functions 2015-04-09 20:54:07 +02:00
Daniel Marjamäki e3bff8ff07 astyle formatting 2015-03-29 21:05:18 +02:00
Dmitry-Me e36ff852cd Don't call abort() in the middle of C++ code 2015-03-26 15:26:08 +03:00
Simon Martin ec1eebf585 Ticket #6587: Never consider a template parameter's default value as an instantiation. 2015-03-21 16:30:00 +01:00
PKEuS 9bafa3bf25 Fixed false positive #6575 2015-03-11 20:25:27 +01:00
PKEuS b2835051df Refactorization: Renamed Token::Match pattern %var% to %name%, implement new pattern %var% which is true if varId > 0. 2015-01-31 12:32:04 +01:00
PKEuS b69528eb80 Bailout in Token::getValueTokenDeadPointer() if reference is used (#6399) 2015-01-30 19:29:37 +01:00
Thomas Jarosch 2bcd675653 Verbose AST dump: Show if token is expanded from macro
I also added the token variable id, but that decreased
readability of the AST tree too much.
2015-01-17 23:20:52 +01:00
PKEuS e39729ffcc Library: Add <container> tag to Libraries, provide configuration for std::vector, std::deque, std::array and STL strings
Token: Added function to jump to the next template argument
2015-01-03 22:18:33 +01:00
Daniel Marjamäki ff11ba9847 Updated copyright year to 2015 2015-01-03 12:14:58 +01:00
Robert Reif 9e60f584d9 Fixed #6321: Implemented function Token::swapWithNext(). 2014-12-27 10:53:26 +01:00
PKEuS 4d81945ac5 Fixed a couple of #6276 integer over/underflow issues 2014-12-09 23:28:22 +01:00
PKEuS 1df1b9c2bd Fixed #5836: Make showing $ in stringified tokens optional 2014-09-29 14:50:00 +02:00
Simon Martin 53b58f0ed9 Refactoring. Use Token::Match instead of hardcoded patterns to increase readability. 2014-09-14 11:26:16 +02:00
PKEuS c678937538 Fixed more false positives of #6056:
- Implemented nextArgument() for usages before < and > are linked
- slightly optimized nextArgument()
2014-08-20 15:02:52 +02:00
Daniel Marjamäki b8e356462a Dead pointer: Fixed FP for subfunction pointer argument 2014-08-14 06:47:19 +02:00
Daniel Marjamäki a2f776b1b7 Dead pointer: Added checking for dead pointer usage when pointer alias local variable that has gone out of scope. 2014-08-05 06:24:23 +02:00
Daniel Marjamäki 47a2b35e98 BufferOverrun: Use ValueFlow string values more 2014-08-04 08:25:10 +02:00
Daniel Marjamäki 79fc549de0 ValueFlow: start adding valueflow handling of strings and pointer aliases 2014-08-03 20:11:22 +02:00
Daniel Marjamäki 544a5957e1 Token: Added utility function getStrSize as a complement to getStrLength 2014-08-01 13:12:18 +02:00
Daniel Marjamäki 404c13ef4b Fixed ValueFlow --debug output 2014-08-01 09:50:30 +02:00
Daniel Marjamäki fdfea717c6 Suspicious string comparison: Refactoring using AST. Fixed FP in Lac. 2014-07-28 14:27:35 +02:00
Daniel Marjamäki 8db5836e3f Fixed #5982 (Add xml dump) 2014-07-14 15:51:45 +02:00
Daniel Marjamäki 954400a382 Add simple xml debug output. When both --xml and --debug is used there will be xml debug output. 2014-07-13 17:21:45 +02:00
Alexander Mai 88890a851c Fix compiler warning (and minor cleanup). 2014-07-05 12:10:23 +02:00
PKEuS b4f0869a71 Reduced Token::Match complexity, better support for complex patterns 2014-07-02 15:25:41 +02:00
PKEuS 817d32f791 Fixed and cleaned up Token::Match engine 2014-07-02 15:25:19 +02:00
Daniel Marjamäki 41baffdda1 Fixed #5850 (Wrong Message on self assignment) 2014-06-28 15:26:22 +02:00
PKEuS 7ea7ee0005 Store Token::_originalName on heap, since it is only used for a small amount of Tokens (reduce memory usage of TokenList by ~12% (x64)) 2014-06-26 11:51:02 +02:00
PKEuS ec1bd420a7 Refactorizations optimizing std::string usage:
1) Added global static const std::string emptyString; object:
-> Replaces some static variables in functions which might be not threadsafe
-> Avoids constructor call (std::string::string(""))
-> Even functions that return an empty string in some branches can return by reference now.
Added to config.h to ensure that it is available everywhere

2) Added overloads for TestFixture::assertEquals for the most common use cases:
-> Moves conversion from const char[] to std::string into a function, reducing code duplication in binary.
2014-06-26 11:51:02 +02:00
PKEuS 8b9daadd25 Replaced static variable isCPP in Token (was not threadsafe):
- Encapsulate parameters passed through AST compiler functions in a struct
-> Reduces maintenance overhead when changing them
-> Contains parameter indicating if the file is C or C++
- Added eKeyword Token type (at the moment, only true for C++ keyword "delete", but should be set for other keywords as well)
2014-06-14 10:28:12 +02:00
PKEuS adf38fcfd0 Further include cleanup 2014-05-24 12:50:04 +02:00
Alexander Mai be9a566d48 Refactoring/small corrections to fix warnings from clang -fsanitize=undefined 'member call on null pointer' 2014-05-20 21:55:08 +02:00
PKEuS d1c4777053 Fixed two bugs in AST compilation (#5830):
- Correctly parse operators .* and ->*
- Support empty branch in ternary expression (a?:c)
2014-05-19 21:54:59 +02:00
Robert Reif 2d2847ddbd Fixed #5764 (Store Token flags in a single variable) 2014-05-06 06:35:48 +02:00
Daniel Marjamäki d17f926422 Merge pull request #294 from simartin/typo_520aaf71
Reinstate error message.
2014-05-04 20:49:01 +02:00
Robert Reif ae96491d6c Fixed #5756 (declspec(nothrow) not supported) 2014-05-04 20:47:20 +02:00
Simon Martin 8519a954a0 Reinstate error message. 2014-05-04 17:06:38 +02:00
Daniel Marjamäki 5a23b739da ValueFlow: Improved bailout when variable is reassigned 2014-05-03 12:49:07 +02:00
Alexander Mai 520aaf71b8 Fix some doxygen comments and add shortcut for tok==NULL to Token::simpleMatch() 2014-04-27 09:32:02 +02:00
Robert Reif 6ff5de2118 Fixed #5697 (Check for throw in __attribute__((nothrow)) function) 2014-04-20 20:40:55 +02:00
PKEuS d9358de8b4 Refactorization: Use templates and rValue references
-> Performance gain of up to 15% on entire checking time (depends on setup; Result was checked with VS12 (x64), matchcompiled version, ran on tinyxml and cppcheck itself)
2014-04-03 15:03:37 +02:00
Dmitry-Me 3244a61cac Macro parameter was not braced. 2014-04-02 09:25:13 +04:00
Daniel Marjamäki 3c64c70ce2 ValueFlow: Added utility functions getValueLE and getValueGE to simplify usage 2014-04-02 06:49:28 +02:00
PKEuS 4e19645d62 Added C++11 keywords / C11 types 'char16_t' and 'char32_t' (#3301) 2014-03-28 18:24:39 +01:00
Dmitry-Me d0b3728328 Get rid of assert in isdigit() when processing cyrillic characters. 2014-03-27 10:23:47 +04:00
PKEuS 5083dd4273 Fixed two visual studio warnings 2014-03-24 18:14:23 +01:00
PKEuS b564986d5d Added missing casts causing assertion failures on Windows (#5391)
-> Changed much more occurences, especially in preprocessor.cpp.
2014-03-18 21:41:47 +01:00
Robert Reif 8c993c1363 Partial fix for #5555. Remember function attributes: pure, const, constructor, destructor 2014-03-14 05:40:17 +01:00
Simon Martin a3d1cac79c Ticket #5373: Keep track whether tokens come from a C or C++ file to properly handle %type% in Token::Match with "delete" 2014-03-08 21:26:06 +01:00
Daniel Marjamäki acf5723bdd AST: improved AST printout when --verbose is used 2014-02-24 17:22:29 +01:00
Lauri Nurmi 70a67eaf85 Change some more 0 literals into nullptr. 2014-02-16 13:38:50 +02:00
Daniel Marjamäki 5fe78d1534 use nullptr in lib/token.cpp 2014-02-15 08:05:54 +01:00
Daniel Marjamäki fd3a8a2a18 Update copyright 2014-02-15 07:45:39 +01:00
Daniel Marjamäki 498cdb8610 added debug output for the value flow 2014-01-18 09:58:32 +01:00
Daniel Marjamäki b2b5590f2b Refactoring: Moved astStringify to the Token class and renamed it to expressionString. This can often be useful when reporting error messages that contains source code. 2014-01-17 18:37:49 +01:00
Daniel Marjamäki a6320a35e0 value flow: added experimental subfunction handling 2014-01-06 16:37:52 +01:00
Daniel Marjamäki 4b72f01e99 clarify calculation: Fixed FP for 'a = (*p ? 1 : 2)' 2013-12-28 11:02:39 +01:00
Daniel Marjamäki a572c0b728 AST : cleanup unused functions 2013-11-06 12:38:58 +01:00
Daniel Marjamäki c505f5ea23 Fixed AST problem for 'if ((a.b&c)==d){}' 2013-11-02 19:18:58 +01:00
Daniel Marjamäki bbdfd8b5c7 Make it possible to create AST, by using the --ast flag 2013-11-02 18:37:35 +01:00
Daniel Marjamäki bb0385321f Fixed #5074 (False positive: Duplicate expression (macro)) 2013-10-13 17:42:06 +02:00
Robert Reif 2de3ebcb1e CheckIO: fixed some more false negatives. Ticket: #4964 2013-09-24 06:43:03 +02:00
Robert Reif 489a3a6e53 Fixed #5015 (strings not being concatinated properly) 2013-09-06 05:36:33 +02:00
Robert Reif 05f2f0e419 CheckIO: improved type info - keep track of original typename. 2013-08-31 06:26:39 +02:00