mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
C#: Sign analysis testcase for unsigned right shift.
This commit is contained in:
42
csharp/ql/test/library-tests/csharp11/SignAnalysis.cs
Normal file
42
csharp/ql/test/library-tests/csharp11/SignAnalysis.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
public class MySignAnalysis
|
||||
{
|
||||
|
||||
public void UnsignedRightShiftSign(int x, int y)
|
||||
{
|
||||
int z;
|
||||
if (x == 0)
|
||||
{
|
||||
z = x >>> y;
|
||||
}
|
||||
|
||||
if (y == 0)
|
||||
{
|
||||
z = x >>> y;
|
||||
}
|
||||
|
||||
if (x > 0 && y == 0)
|
||||
{
|
||||
z = x >>> y;
|
||||
}
|
||||
|
||||
if (x > 0 && y > 0)
|
||||
{
|
||||
z = x >>> y;
|
||||
}
|
||||
|
||||
if (x > 0 && y < 0)
|
||||
{
|
||||
z = x >>> y;
|
||||
}
|
||||
|
||||
if (x < 0 && y > 0)
|
||||
{
|
||||
z = x >>> y;
|
||||
}
|
||||
|
||||
if (x < 0 && y < 0)
|
||||
{
|
||||
z = x >>> y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
| SignAnalysis.cs:9:17:9:23 | ... >>> ... | 0 |
|
||||
| SignAnalysis.cs:14:17:14:23 | ... >>> ... | + - 0 |
|
||||
| SignAnalysis.cs:19:17:19:23 | ... >>> ... | + |
|
||||
| SignAnalysis.cs:24:17:24:23 | ... >>> ... | + 0 |
|
||||
| SignAnalysis.cs:29:17:29:23 | ... >>> ... | + 0 |
|
||||
| SignAnalysis.cs:34:17:34:23 | ... >>> ... | + - |
|
||||
| SignAnalysis.cs:39:17:39:23 | ... >>> ... | + - |
|
||||
9
csharp/ql/test/library-tests/csharp11/signAnalysis.ql
Normal file
9
csharp/ql/test/library-tests/csharp11/signAnalysis.ql
Normal file
@@ -0,0 +1,9 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.dataflow.internal.rangeanalysis.SignAnalysisCommon as Common
|
||||
|
||||
from ControlFlow::Nodes::ExprNode e, Expr expr
|
||||
where
|
||||
e.getExpr() = expr and
|
||||
expr.getFile().getStem() = "SignAnalysis" and
|
||||
expr instanceof UnsignedRightShiftExpr
|
||||
select e, strictconcat(string s | s = Common::exprSign(e).toString() | s, " ")
|
||||
Reference in New Issue
Block a user