Merge pull request #672 from wilzbach/fix-671
Fix #671 - False positive in infinite range check merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
commit
0ec1e9557a
|
@ -62,6 +62,8 @@ final class IncorrectInfiniteRangeCheck : BaseAnalyzer
|
|||
|
||||
override void visit(const ReturnStatement rs)
|
||||
{
|
||||
if (inStruct == 0 || line == size_t.max) // not within a struct yet
|
||||
return;
|
||||
if (!rs.expression || rs.expression.items.length != 1)
|
||||
return;
|
||||
UnaryExpression unary = cast(UnaryExpression) rs.expression.items[0];
|
||||
|
@ -82,7 +84,7 @@ private:
|
|||
uint inStruct;
|
||||
enum string KEY = "dscanner.suspicious.incorrect_infinite_range";
|
||||
enum string MESSAGE = "Use `enum bool empty = false;` to define an infinite range.";
|
||||
size_t line;
|
||||
size_t line = size_t.max;
|
||||
size_t column;
|
||||
}
|
||||
|
||||
|
@ -123,8 +125,6 @@ class C { bool empty() { return false; } } // [warn]: %1$s
|
|||
|
||||
}c
|
||||
.format(IncorrectInfiniteRangeCheck.MESSAGE), sac);
|
||||
|
||||
stderr.writeln("Unittest for IncorrectInfiniteRangeCheck passed.");
|
||||
}
|
||||
|
||||
// test for https://github.com/dlang-community/D-Scanner/issues/656
|
||||
|
@ -136,3 +136,23 @@ version(none) struct Foo
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
import std.stdio : stderr;
|
||||
import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
|
||||
import std.format : format;
|
||||
|
||||
StaticAnalysisConfig sac = disabledConfig();
|
||||
sac.incorrect_infinite_range_check = Check.enabled;
|
||||
assertAnalyzerWarnings(q{
|
||||
enum isAllZeroBits = ()
|
||||
{
|
||||
if (true)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}();
|
||||
}, sac);
|
||||
stderr.writeln("Unittest for IncorrectInfiniteRangeCheck passed.");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue