Commit Graph

345 Commits

Author SHA1 Message Date
chrchr-github 109a031ec7
Fix #11195 Add redundantContinue check (#4283) 2022-07-16 16:02:58 +02:00
PKEuS 9eb16e1002
Replaced check for pipe() buffer size by ordinary CheckBufferOverrun, provide required Library configuration option (#4183)
Merged from LCppC.
2022-06-19 12:01:55 +02:00
Daniel Marjamäki 1f6554e2e8 Update copyright year 2022-05-21 12:18:27 +02:00
chrchr-github 54f832a2fe
Fix #10569 FN: duplicateExpression with multiple strings compared (#4087) 2022-05-09 21:05:35 +02:00
chrchr-github 034140e7e1
Fix #10991 FN: Redundant pointer operation (#4054) 2022-04-27 19:52:56 +02:00
Oliver Stöneberg 6e57cc4323
small utils.h cleanup (#3821) 2022-02-11 19:44:08 +01:00
Oliver Stöneberg f32583e097
removed OVERRIDE and FINAL defines and use the keywords directly (#3767) 2022-02-10 23:02:24 +01:00
Paul Fultz II 7f358b2bed
Format with uncrustify (#3388) 2021-08-07 20:51:18 +02:00
Daniel Marjamäki eb9a251a4c const variables/parameters; Improved check to handle pointers also (misra 8.13) 2021-07-18 10:59:52 +02:00
Daniel Marjamäki 6234b5438e New check: Writing overlapping data, detect undefined behavior 2021-07-05 22:07:41 +02:00
Daniel Marjamäki c489626167 updated copyright year 2021-07-04 08:09:11 +02:00
Daniel Marjamäki 9769afe434 knownConditionTrueFalse; avoid several warnings when nonzero expression is compared to see if it is positive or negative 2021-06-25 16:25:25 +02:00
Oliver Stöneberg 6397e29f84
cleaned up includes based on include-what-you-use (#3141) 2021-04-03 21:30:50 +02:00
Daniel Marjamäki 5578b09452 More fixing for #9914. New warning id and warning message when variable expression is explicitly hidden. 2020-09-26 13:49:47 +02:00
Daniel Marjamäki 05b0a0f970 Make duplicateAssignExpression warnings inconclusive for 'x&&false' etc. (#9914) 2020-09-26 10:50:58 +02:00
Daniel Marjamäki 514b7f4da4 Fixed #9906 (False positive: constParameter (function pointer)) 2020-09-23 22:10:47 +02:00
Oliver Stöneberg 2e24cc1434
checkother.h: added missing newline in classInfo - fixes tests (#2818) 2020-09-21 21:44:46 +02:00
Daniel Marjamäki 107ee57e7a Fixed #9909 (False positive: knownArgument for calculation 'self->maxsize * sizeof(intptr_t)') 2020-09-21 20:02:55 +02:00
Daniel Marjamäki ddd21a260f Fixed #6978 (False positive: unusedLabel shown for labels that are used in some preprocessor configurations) 2020-06-30 18:26:24 +02:00
Oliver Stöneberg 37bc0483a4
made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
miltolstoy a9d8b3495d
feat: add modulo of one check (#9528) (#2650) 2020-05-20 23:01:32 +02:00
Daniel Marjamäki 08ddd84780 Update copyright year 2020-05-10 11:16:32 +02:00
Daniel Marjamäki 3e0218299b Revert "Update copyright year"
This reverts commit 6eec6c4bd5.
2020-05-10 11:13:05 +02:00
Daniel Marjamäki 6eec6c4bd5 Update copyright year 2020-05-10 11:11:34 +02:00
Paul Fultz II d88557bc18
Rename constArgument to knownArgument (#2616) 2020-04-22 09:13:35 +02:00
Oliver Stöneberg 2c1e36e63e
cleaned up includes based on include-what-you-use (#2600)
* cleaned up includes based on include-what-you-use

* check.h: trying to work around Visual Studio 2012 bug

* fixed Visual Studio compilation
2020-04-13 13:44:48 +02:00
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
Rikard Falkeborn 38dea4719b Fix #9166 (print proper types in invalidCast message) (#2347)
* Fix #9166 (print proper types in invalidCast message)

* Use ValueType->str()

* astyle

* Set default sign to avoid issues on different platforms
2019-11-11 07:17:50 +01:00
Daniel Marjamäki 82eec11898 Created redundantInitialization id 2019-08-25 09:45:39 +02:00
Paul Fultz II bb52a63c4e Add check for const variables
When a local reference is declared, this will check if that local reference can be declared as `const`.
2019-07-24 09:59:01 +02:00
Daniel Marjamäki d11d6f112e Detect shadowed arguments 2019-07-17 17:08:42 +02:00
Daniel Marjamäki ef73a10e30 Replace 'unsigned' with 'nonneg' in checkother 2019-07-16 09:10:10 +02:00
Daniel Marjamäki 3dc34f1515 Disable all simplified checks 2019-03-16 09:17:50 +01:00
Daniel Marjamäki 6eaf2c03d9 CheckOther::checkInvalidFree: Move check to normal checking. And clarify the message. 2019-03-07 06:35:44 +01:00
Daniel Marjamäki 17e73fd144 Move CheckOther::checkComparisonFunctionIsAlwaysTrueOrFalse to Normal checking 2019-03-06 21:27:19 +01:00
Daniel Marjamäki f20936ed8a Moved CheckOther::checkPassByReference to normal checking 2019-03-06 20:59:45 +01:00
Daniel Marjamäki 572d7eb86c Moved CheckOther::clarifyCalculation to normal checking 2019-03-06 20:43:28 +01:00
Daniel Marjamäki ee9053f219 Moved CheckOther::checkRedundantCopy() to normal checking 2019-03-06 20:38:13 +01:00
Daniel Marjamäki 37814513f8 Revert "Moved all simplified CheckOther checks from simplified to normal checking"
This reverts commit 2900690881.
2019-03-06 07:08:56 +01:00
Daniel Marjamäki 2900690881 Moved all simplified CheckOther checks from simplified to normal checking 2019-03-06 06:33:51 +01:00
Daniel Marjamäki 06c2019676 Moved CheckOther::checkPipeParameterSize from simplified to normal checking 2019-03-06 06:28:13 +01:00
Paul Fultz II fd3c1fd040 Fix issue 1777: Undefined Behavior: Comparing pointers to different objects
This uses the lifetime analysis to check when comparing pointer that point to different objects:

```cpp
int main(void)
{
    int foo[10];
    int bar[10];
    int diff;

    if(foo > bar)   // Undefined Behavior
    {
       diff = 1;
    }

    return 0;
}
```
2019-02-23 08:32:08 +01:00
Paul Fultz II cf1ad5087a Extend constStatement checker
This reworks constStatement to find more issues. It catches issue [8827](https://trac.cppcheck.net/ticket/8827):

```cpp
extern void foo(int,const char*,int);
void f(int value)
{
        foo(42,"test",42),(value&42);
}
```

It also catches from issue [8451](https://trac.cppcheck.net/ticket/8451):

```cpp
void f1(int x) {
    1;
    (1);
    (char)1;
    ((char)1);
    !x;
    (!x);
    ~x;
}
```

And also:

```cpp
void f(int x) {
    x;
}
```

The other examples are not caught due to incomplete AST.
2019-02-15 13:31:40 +01:00
Daniel Marjamäki bd7790fd8c Update copyright year 2019-02-09 07:24:06 +01:00
rikardfalkeborn 7779a9186e Use valueflow in unsigned less than zero checker (#1630)
The unsigned less than zero checker looked for patterns like "<= 0".
Switching to use valueflow improves the checker in a few aspects.

First, it removes false positives where instead of 0, the code is using
0L, 0U, etc. Instead of having to hard code the different variants of 0,
valueflow handles this automatically. This fixes FPs on the form

	uint32_t value = 0xFUL;
	void f() {
  		if (value < 0u)
		{
			value = 0u;
		}
	}

where 0u was previously not recognized by the checker. This fixes #8836.

Morover, it makes it possible to handle templates properly. In commit
fa076598ad, all warnings inside templates
were made inconclusive, since the checker had no idea if "0" came from
a template parameter or not.

This makes it possible to not warn for the following case which was
reported as a FP in #3233

	template<int n> void foo(unsigned int x) {
	if (x <= n);
	}
	foo<0>();

but give a warning for the following case

	template<int n> void foo(unsigned int x) {
	if (x <= 0);
	}

Previously, both these cases gave inconclusive warnings.

Finally, it makes it possible to give warnings for the following code:

	void f(unsigned x) {
		int y = 0;
		if (x <= y) {}
	}

Also, previously, the checker for unsigned variables larger than 0, the
checker used the string of the astoperand. This meant that for code like
the following:

	void f(unsigned x, unsigned y) {
		if (x -y >= 0) {}
	}

cppcheck would output

	[unsigned-expression-positive.c] (style) Unsigned variable '-' can't be negative so it is unnecessary to test it.

using expressionString() instead gives a better error message

        [unsigned-expression-positive.c] (style) Unsigned expression 'x-z' can't be negative so it is unnecessary to test it.
2019-01-31 09:30:29 +01:00
Daniel Marjamäki 8b5f36670a Introduce macro OVERRIDE for gcc-4.6 compatibility. 2019-01-12 07:37:42 +01:00
Paul Fultz II 9b973e652c Issue 8830: New check: Function argument evaluates to constant value
Add a check for function arguments that can be constant:

```cpp
extern void bar(int);
void f(int x) {
   bar((x & 0x01) >> 7); // function 'bar' is always called with a '0'-argument
}
```
2018-12-17 06:04:24 +01:00
Daniel Marjamäki 6734571f06 Refactoring: Create FwdAnalysis class in astutils 2018-12-02 17:01:52 +01:00
Daniel Marjamäki 88785dda02 Refactoring the redundant assignments check 2018-12-02 11:41:27 +01:00
Daniel Marjamäki 866688c70a Rewriting redundantAssignment checker 2018-11-24 10:03:54 +01:00