Commit Graph

308 Commits

Author SHA1 Message Date
Daniel Marjamäki 392a06a44b AST: better handling of '(struct X){...}' 2017-04-06 21:28:13 +02:00
Daniel Marjamäki e6ed08c4d8 Fixed #7976 (Internal error. Token::astOperand1() cyclic dependency. (ticket nr 2, new regression)) 2017-04-05 11:00:02 +02:00
Daniel Marjamäki abb43b6a81 Fixed #7934 (Wrong AST for 'for (i=0;cond;({min(x,10);}))') 2017-04-02 19:44:33 +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
Daniel Marjamäki c18fe8262b Fixed #7934 (Wrong AST for 'for (i=0;cond;({min(x,10);}))') 2017-03-19 07:26:11 +01:00
Daniel Marjamäki ecc59859e1 Don't simplify _Bool in TokenList 2017-03-04 11:13:28 +01:00
Daniel Marjamäki f0c353abcb TokenList: append 'U' if needed on hexvalues 2017-03-04 08:47:53 +01:00
Matthias Krüger 064a4aa4cc improve constness of functions as per cppchecks suggestions. 2017-01-07 14:31:03 +01:00
Stefan Weil 57b57428c2 Fix some typos in comments (found by codespell)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2016-11-27 11:40:42 +01:00
Daniel Marjamäki c329887bfe use const 2016-11-20 15:44:20 +01:00
Frank Zingsheim c8ff96fe8f Fixed #6180 (Usage of variable after std::move or std::forward) 2016-11-20 15:14:49 +01:00
Simon Martin f816fb811e Ticket #7680: Properly handle ::delete during memory leak checks. 2016-09-10 14:55:50 +02:00
Robert Reif 100c4276ea Fixed #7424 (value type: wrong sign) 2016-03-18 10:30:57 +01:00
Alexander Mai 89c9528fdc Small optimization of TokenList::validateAst() 2016-02-02 08:55:26 +01:00
Alexander Mai a288d5eb16 #7027 TokenList::validateAst() did not detect broken AST with endless recursion 2016-01-31 22:16:58 +01:00
Daniel Marjamäki c0056d2455 Fixed #7347 (AST: wrong ast when template variable is declared and initiailized in if 'if (A::B<C> abc = 123)') 2016-01-26 10:40:44 +01:00
Daniel Marjamäki 7663b6ee75 Fixed #7348 (AST: wrong ast for cast that starts with :: '(::X*)x;') 2016-01-25 10:29:24 +01:00
Daniel Marjamäki 79e663dd6f Settings: Remove '_' prefix for public member variables 2016-01-03 16:18:17 +01:00
Daniel Marjamäki 91d0f0fee0 astyle formatting
[ci skip]
2016-01-03 09:38:03 +01:00
Daniel Marjamäki ed12b4dc44 Fixed #7253 (AST wrong on nested reinterpret_cast) 2016-01-03 09:37:38 +01:00
Lauri Nurmi 996c9244d8 Update copyright year to 2007-2016. 2016-01-01 15:34:45 +02:00
Alexander Mai 5b6758b03b Add some debugging code (inspired by #6021) 2015-12-27 17:38:15 +01:00
Daniel Marjamäki f09dded7b1 TokenList: Better handling of '1++a' and 'a++1' 2015-12-27 14:57:22 +01:00
Alexander Mai e9635fd393 #7236 segmentation fault (invalid code) in ValueFlow::setValues. #7237 segmentation fault (invalid code) in Tokenizer::setVarIdClassDeclaration 2015-12-26 23:51:10 +01:00
amai2012 081f443b2a #7235 segmentation fault (invalid code) in TokenList::createAst 2015-12-26 20:26:07 +01:00
Dmitry-Me 05cb4e16fe Fix misspelled word 2015-12-25 11:51:08 +03:00
Dmitry-Me bd45c71d8d No need to clear empty strings 2015-12-24 10:16:58 +03:00
Daniel Marjamäki 3f386af21c astyle formatting 2015-12-23 10:26:12 +01:00
Alexander Mai 28a625abd8 #7218 Improve performance in TokenList::validateAst(): Keep a list of 'verified' tokens during recursion check. 2015-12-19 20:36:30 +01:00
Dmitry-Me 4a8a5d4460 Fix C4706 assignment within conditional 2015-12-15 11:34:04 +03:00
Alexander Mai 96531d6ffe TokenList::createAst() doesn't validate itself anymore. Remove some duplicated code and fix glitch in TestGarbage::garbageCode162 2015-12-12 20:01:03 +01:00
Alexander Mai 5b2dacb4b4 Correct travis and compiler warnings and comments 2015-12-12 16:08:52 +01:00
Alexander Mai 9a847d7b14 #7208 Cppcheck hangs with 100% CPU load in CheckOther::checkNegativeBitwiseShift (invalidcode). TokenList::validateAst() is running consistency checks on AST 2015-12-12 15:39:38 +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
PKEuS 1566b72c5b Fixed broken AST for simple expressions with delete operator.
Fixed cppcheck internal warning
2015-11-18 21:37:37 +01:00
Daniel Marjamäki 0f9d90d2be Changed Copyrights. Removed my name. 2015-11-18 20:04:50 +01:00
Alexander Mai 5318970f1e #7109 segmentation fault (invalid code) in TokenList::createAst 2015-11-08 15:09:39 +01:00
PKEuS be36539ad7 Fixed AST generation for C++11-style initialization (#6528) 2015-11-06 17:34:26 +01:00
Daniel Marjamäki fc2bf2ef08 Fixed #7065 (AST: More explicit handling of lambda functions, generate ast for ';new Fred;') 2015-10-20 23:55:29 +02: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 9be284e80f AST: proper operator precedence for c++11 initializer {} and :: 2015-10-18 16:58:15 +02:00
Daniel Marjamäki 9bb2af1893 Fixed #7059 (AST: handle C++ initialization with {} better) 2015-10-18 13:43:39 +02:00
Daniel Marjamäki b81b21a57b Fixed #7051 (hang in ast code (failed to create a proper testcase)) 2015-10-18 11:42:18 +02:00
Daniel Marjamäki 30af2fcd73 iscast: handle '(ulong)~0' better 2015-10-17 18:25:27 +02:00
Daniel Marjamäki 507727e07f Fixed Travis 2015-10-17 17:15:19 +02:00
Daniel Marjamäki c88297c971 Fixed #7054 (AST: handle C++ initialization with {} better) 2015-10-17 17:03:24 +02:00
PKEuS 05b5275110 Improved AST:
- Fixed TODO for ternary operator. Add parantheses between ? and : where necessary as a preparation for createAst()
- Improved AST validation:
-- Better message for binary operator with only one operand
-- Ensure ? has : as second operand (#7035)
2015-10-12 19:21:48 +02:00
Daniel Marjamäki 40fffddb83 avoid some fixes for noisy signedness warnings 2015-10-11 12:36:23 +02:00
PKEuS ab8afec3eb Refactorizations:
- Avoid unnecessary loop iterations
- Avoid unnecessary condition checking
- Reduced code duplication in symboldatabase.cpp
2015-08-16 14:23:07 +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 35eb1a393d AST: handle concatening of strings better. this is not ideal but better. 2015-07-27 13:13:30 +02:00
Alexander Mai bbec54db8e Implement MathLib::isFloatHex to detect C99 hexadecimal floating pointer literals. Rename MathLib::isHex to MathLib::isIntHex 2015-07-26 08:06:56 +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 8ffa917fa2 Fixed #6863 (AST: wrong handling of assignment between ? and :) 2015-07-24 13:02:00 +02:00
Daniel Marjamäki 8a72bb8aa8 AST: Fixed AST for struct initialisation 2015-07-21 11:40:42 +02:00
amai2012 ac1f0301c0 #6791 segmentation fault (invalid code) in TokenList::createAst. Fix null pointer access 2015-06-25 08:57:09 +02:00
Daniel Marjamäki a884362817 Fixed #6752 (wrong AST when there is lambda function) 2015-06-17 19:32:44 +02:00
XhmikosR 8fc4456fb4 Fix compilation error with MSVC 2013 after a7b82b5. 2015-06-15 16:06:18 +03:00
Alexander Mai a7b82b5c28 Refactoring to address some issues from #5895 (handling of unsigned numbers). Also adding a TODO testcase since the real issue (FP) is still not fixed 2015-06-13 18:08:13 +02:00
Alexander Mai 133d8f9a91 #6706 segmentation fault (invalid code) in tokenlist::compilePrecedence3. Local fix to prevent acess to NULL-token 2015-05-27 21:39:31 +02:00
Alexander Mai e28e9be82f Add TODO testcase for #5738. Refactoring: add some const 2015-05-25 08:20:14 +02:00
PKEuS 0d37c4df04 Fixed three unique crashs on garbage code (#6613).
Removed redundant copy of string in templatesimplifier.cpp
2015-04-01 12:43:24 +02:00
Daniel Marjamäki e251a99817 AST: fix handling of sizeof. ticket #6515 2015-02-18 19:56:13 +01:00
PKEuS f78744ac30 Fixed AST generation if expression starts with ternary operator 2015-02-01 14:02:19 +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
orbitcowboy 5a8574cc05 tokenlist::createAst(); should not be const. 2015-01-20 11:22:22 +01:00
orbitcowboy bf1565bd34 Fixed inconclusive warnings regarding const correctness. 2015-01-20 09:09:16 +01:00
Daniel Marjamäki ff11ba9847 Updated copyright year to 2015 2015-01-03 12:14:58 +01:00
Alexander Mai 5300ba2074 Make single-argument constructors explicit 2014-11-13 21:39:14 +01:00
Daniel Marjamäki 7107286be6 Fixed #5891 (AST: wrong ast generated for 'x = (int)(double(123)*i);') 2014-10-16 15:57:05 +02:00
Daniel Marjamäki 94c677905b ast: don't hang when invalid code with new is found 'new (var1,var2,var3);' 2014-10-13 19:12:20 +02:00
Daniel Marjamäki aac9e66147 AST: fixed ast for 'new (char *)[10]' 2014-10-12 12:57:01 +02:00
Daniel Marjamäki f72a8d3f15 AST: fixed ast for 'a(new A(1)), b(new B(2))' 2014-10-12 12:13:01 +02:00
Daniel Marjamäki 649e2dfa97 AST: fixed ast for 'a = new (b) ::X;' 2014-10-12 11:12:25 +02:00
Daniel Marjamäki f96ea94048 AST: fixed ast for 'a(new (X), 5);' 2014-10-12 10:20:03 +02:00
Daniel Marjamäki c537c98751 AST: fixed ast for 'a(new (X));' 2014-10-12 09:24:43 +02:00
Daniel Marjamäki 489fc6cce7 AST: more fixes of new statements in clang test suite. some of it is not handled very well. 2014-10-11 13:20:48 +02:00
Daniel Marjamäki 4783a67042 AST: fixes for more new statements from clang test suite 2014-10-11 11:27:13 +02:00
Daniel Marjamäki e6708c1ae2 AST: fixed hang for 'new (int S::*[3][4][5])()' (clang test suite) 2014-10-11 08:32:49 +02:00
Daniel Marjamäki 5891bae59e AST: generilized handling of auto usage in new statement 2014-10-10 19:05:31 +02:00
Daniel Marjamäki 66d4614a87 AST: don't hang when using auto in new statement 2014-10-10 12:47:01 +02:00
Daniel Marjamäki b5faf3a0cc AST: improved handling of new 2014-10-10 10:37:54 +02:00
Daniel Marjamäki cca003490b Fixed #6203 (AST: fix problem with '; static_cast<...') 2014-10-10 08:18:24 +02:00
Martin Ettl 2ca47601cd Running astyle 2014-09-28 22:05:05 +02:00
Martin Ettl b677d3d17f Fix crash on garbage code in tokenlist. The corresponding backtrace along with a testcase is hosted at: https://github.com/orbitcowboy/cppcheck_crash_files/blob/master/crash220.cpp 2014-09-28 22:04:25 +02:00
PKEuS 58fe668fc4 Fixed AST for operator:: after template (#6195) 2014-09-29 11:01:37 +02:00
PKEuS 55b14853d0 Fixed AST: Compile expression inside [] brackets of operator new. (#6193) 2014-09-29 10:26:15 +02:00
Daniel Marjamäki 29a49d0641 removed some redundant null pointer checks before calling Token::Match 2014-09-14 11:35:04 +02:00
Simon Martin 53b58f0ed9 Refactoring. Use Token::Match instead of hardcoded patterns to increase readability. 2014-09-14 11:26:16 +02:00
Daniel Marjamäki 0ab7abded1 AST: fixed cast for 'return (long long)c << 40;' 2014-09-12 06:43:52 +02:00
PKEuS e4a81f9666 Improved checksum algorithm to fix configurations being purged by coincidence (#6126):
- Better distribution of values by rotating the bits of the checksum for each token
2014-09-03 23:10:38 +02:00
PKEuS bf2f76e70c Detect and purge duplicate configurations by calculating a checksum. 2014-09-02 22:35:52 +02:00
PKEuS 80df3dc642 Disabled several checks and simplifications for C code, if they are C++-only. Do not match arguments for C code, since there can't be overloads. 2014-09-01 18:43:24 +02:00
Daniel Marjamäki cd75b2d83d AST: fix hang for code 'MACRO({.x=1,.y=2})' 2014-08-25 19:10:16 +02:00
Daniel Marjamäki 1060b30e52 AST: better AST for placement new expression 'new (a) MyClass;' 2014-08-23 13:21:36 +02:00
PKEuS a1b7ab277b Changed handling of unhandled characters:
- Don't abort checking (reverts 42140b6488)
- Modified error message: New Id unhandledCharacter, removed redundant line information, improved message text
2014-08-08 09:49:09 +02:00
PKEuS 95afa51b24 Fixed crash #5991: Don't crash when lambda is incomplete
Fixed crash #6004: Support struct initializations in AST
2014-07-31 23:15:36 +02:00
Dmitry-Me ba3757dfd3 Bring variables decalaration to where they are really needed. 2014-07-10 11:23:14 +04:00
Alexander Mai df95cd09f0 Fix compiler warnings about type mismatch 2014-07-08 21:47:22 +02:00
amai2012 9b38ae73c1 Attempt to fix 2 Coverity messages.
Replace a few unsigned int by std::size_t
2014-07-07 21:25:30 +02:00
Daniel Marjamäki 72992c7973 AST: fixed ast for '++i;' 2014-06-26 17:31:57 +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 e80104327a AST: Fixed detection of operator new/delete - don't hang when C code is checked as C++ (#5910) 2014-06-26 09:19:57 +02:00
PKEuS 3a89e5d65f Fixed cppcheck warnings introduced by previous commit 2014-06-24 19:51:47 +02:00
PKEuS 1b5d127373 Cache results for TokenList::isC() and TokenList::isCPP() to avoid redundant calls to Path::isCPP()/isC(), which perform slow string operations (conversion to lowercase, substring, comparisons)
-> Speedup of 2% on self-checking cppcheck-core (MSVC12, x64, not matchcompiled)
2014-06-24 17:42:39 +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 2455b76abd Fixed lots of bugs in the AST:
- Support new and delete
- Properly handle "..."
- References and rValue references as function parameters
- Destructor definitions
2014-06-04 18:47:56 +02:00
PKEuS d93d7401c6 Moved getSourceFilePath(), isC() and isCPP() from Tokenizer to TokenList
Conflicts:
	lib/tokenize.cpp
2014-06-04 18:36:25 +02:00
Daniel Marjamäki 46bf23aa6d TokenList: added assertion that makes sure the Preprocessor doesn't let through extended ascii wrongly. 2014-05-31 18:02:19 +02:00
PKEuS 8f083af1e4 Attempt to fix travis build 2014-05-25 22:11:56 +02:00
PKEuS a407b55945 Added support for lambdas to AST
Fixed bug that return statement left an operand on the stack
2014-05-25 21:55:39 +02:00
PKEuS 55c87248ba Fixed crash on complex cast. 2014-05-24 20:21:08 +02:00
PKEuS 38aaa46804 Stabilized AST:
- Fixed broken simplification causing crashs when cast was followed by unary minus (real world examples from arch/parisc/math-emu/ (linux-kernel))
- Stabilized determination of unary and binary operators
2014-05-24 19:05:04 +02:00
PKEuS b78131cfcf Improved cast detection in AST:
-> Make use of it in checkother.cpp

Use tokenizer simplification instead of reimplementation for test suite
2014-05-24 11:29:32 +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
Philipp Kloke ed7d0b321b Bugfixes for AST and AST testing:
- Validate AST in test suite: Check for operand1 being set if operand2 is non-zero
- Fixed buggy unit tests in AST
- Fixed detection unary operator* after return statement (MPC-HC false positive)
2014-05-19 11:17:37 +02:00
PKEuS 683d0b7e82 Partially rewritten AST compilation:
- More straightforward approach for handling right-to-left associativity
 - More straightforward approach to handling unary operators
 - Improved handling of brackets

This fixes #5784, #5795, #5797, #5799, #5810 and a bunch of other problems
2014-05-18 12:10:39 +02:00
PKEuS a3bb8bf39c AST: Parse ternary and assignment operators as right-to-left and on the same precedence level 2014-05-11 17:50:58 +02:00
PKEuS 70dfb55f21 Simplified some Token::Match patterns 2014-05-11 17:50:58 +02:00
Daniel Marjamäki 9fc8bdcbac Fixed #5770 (AST: better handling of 'a.b[c.d]==0') 2014-05-08 06:48:53 +02:00
Robert Reif 2d2847ddbd Fixed #5764 (Store Token flags in a single variable) 2014-05-06 06:35:48 +02:00
Robert Reif ae96491d6c Fixed #5756 (declspec(nothrow) not supported) 2014-05-04 20:47:20 +02:00
Daniel Marjamäki 7d583e639c AST: Fixed handling of '(((typeof(x))*)0)' 2014-05-04 18:36:04 +02:00
Daniel Marjamäki 5a23b739da ValueFlow: Improved bailout when variable is reassigned 2014-05-03 12:49:07 +02:00
Daniel Marjamäki 4b7aaba159 AST: assignment operators are executed from right to left 2014-05-03 12:08:42 +02:00
Daniel Marjamäki 648479d909 AST: Fixed tree for 'a.b[5]' 2014-04-29 06:09:26 +02:00
Daniel Marjamäki d279f3fb41 Fixed #5736 (AST: proper handling of 'a=(b).c;') 2014-04-27 18:03:50 +02:00
Daniel Marjamäki 9f2e37da37 AST: fixed 'a.b++' and '*c[5]--' 2014-04-27 16:02:24 +02:00
Daniel Marjamäki 11856b51aa AST: Fixed handling of 'a=b(c**)+1' 2014-04-26 13:32:08 +02:00
Daniel Marjamäki c34616a6ba AST: Fixed handling of 'a = b.c[++(d.e)];' 2014-04-26 13:16:34 +02:00
Frank Zingsheim ffa55bbaa0 Fixed #5725 (FP: multicondition Expression is always false because 'else if' in pngwrite.cxx (LibreOffice)) 2014-04-26 11:59:38 +02:00
Daniel Marjamäki 8602d13dc9 Fixed #5722 (AST: wrong handling of 'x = ((a[i])->getx)();' - the 'x' is an operand of the =) 2014-04-25 06:06:54 +02:00
Daniel Marjamäki c98beafb6d Fixed #5675 (wrong AST generated for 'a>>=b') 2014-04-21 13:05:34 +02:00
Robert Reif 6ff5de2118 Fixed #5697 (Check for throw in __attribute__((nothrow)) function) 2014-04-20 20:40:55 +02:00
Daniel Marjamäki 5c116c622d AST: Fixed iscast detection in '*((DWORD*)&buf[0])' 2014-04-15 15:46:26 +02:00
Daniel Marjamäki 4b6164087e Use constant instead of magic number for AST recursion limit
[ci skip]
2014-04-15 06:31:09 +02:00
Daniel Marjamäki cb830cb999 Code cleanup of stack depth tracking. Replaced class with simple POD variable. 2014-04-15 06:18:15 +02:00
Alexander Mai 40be775efa #5592 (fix implementation detail to avoid warnings from cppcheck) 2014-04-13 13:08:38 +02:00
Alexander Mai 547803f581 #5592 - crash: gcc: testsuit: gcc.c-torture/compile/limits-declparen.c (Limit stack depth below createAst() 2014-04-13 12:47:54 +02:00
Daniel Marjamäki 456e33fc7b Code cleanup
[ci skip]
2014-04-05 08:27:52 +02:00
Daniel Marjamäki 049d68ae7d AST: Fixed bad syntax tree for 'if (x()[0]==1);' 2014-04-05 08:03:24 +02:00
PKEuS e9411e05ba Refactorized inefficient usage of std::string and const char[]. 2014-04-02 13:56:34 +02:00
Daniel Marjamäki 484483bd5d AST: fixed ast for 'for (*x=0;y;z)' 2014-03-31 17:16:13 +02:00
Robert Reif 8c993c1363 Partial fix for #5555. Remember function attributes: pure, const, constructor, destructor 2014-03-14 05:40:17 +01:00
Frank Zingsheim 5e0a575091 Optimization: tokenlist::addtoken 2014-03-09 17:54:49 +01:00
Daniel Marjamäki 8550289722 Fixed #5452 (AST: wrong handling of unary ::) 2014-02-25 06:36:10 +01:00
Daniel Marjamäki c050a92bae Fixed #5468 (crash: freebsd: llvm/RegionPrinter.cpp - AST failure) 2014-02-17 17:37:39 +01:00
Lauri Nurmi 70a67eaf85 Change some more 0 literals into nullptr. 2014-02-16 13:38:50 +02:00