Fix #671 - False positive in infinite range check
This commit is contained in:
parent
103a327a60
commit
cd545d5090
|
@ -62,6 +62,8 @@ final class IncorrectInfiniteRangeCheck : BaseAnalyzer
|
||||||
|
|
||||||
override void visit(const ReturnStatement rs)
|
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)
|
if (!rs.expression || rs.expression.items.length != 1)
|
||||||
return;
|
return;
|
||||||
UnaryExpression unary = cast(UnaryExpression) rs.expression.items[0];
|
UnaryExpression unary = cast(UnaryExpression) rs.expression.items[0];
|
||||||
|
@ -82,7 +84,7 @@ private:
|
||||||
uint inStruct;
|
uint inStruct;
|
||||||
enum string KEY = "dscanner.suspicious.incorrect_infinite_range";
|
enum string KEY = "dscanner.suspicious.incorrect_infinite_range";
|
||||||
enum string MESSAGE = "Use `enum bool empty = false;` to define an 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;
|
size_t column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,8 +125,6 @@ class C { bool empty() { return false; } } // [warn]: %1$s
|
||||||
|
|
||||||
}c
|
}c
|
||||||
.format(IncorrectInfiniteRangeCheck.MESSAGE), sac);
|
.format(IncorrectInfiniteRangeCheck.MESSAGE), sac);
|
||||||
|
|
||||||
stderr.writeln("Unittest for IncorrectInfiniteRangeCheck passed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test for https://github.com/dlang-community/D-Scanner/issues/656
|
// test for https://github.com/dlang-community/D-Scanner/issues/656
|
||||||
|
@ -136,3 +136,23 @@ version(none) struct Foo
|
||||||
return;
|
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