Skip to content

Commit c15c216

Browse files
author
thibaut hansmann
committed
C/C++ : change Variable and ArrayType name + Add detection for Uint 32 and 64
1 parent 83e26f4 commit c15c216

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

cpp/ql/src/experimental/Best Practices/WrongUintAccess.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</overview>
99

1010
<recommendation>
11-
<p>Use a Uint8 instead</p>
11+
<p>Use a int with a lower bit size instead. For instance in this example use a 8 bit int.</p>
1212
</recommendation>
1313

1414
<example>

cpp/ql/src/experimental/Best Practices/WrongUintAccess.ql

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
*/
99

1010
import cpp
11-
import semmle.code.cpp.controlflow.SSA
1211

1312
from
14-
Variable E, ArrayExpr useExpr, ArrayType defExpr, VariableDeclarationEntry def, VariableAccess use
13+
Variable var, ArrayExpr useExpr, VariableDeclarationEntry def, ArrayType defLine, VariableAccess use
1514
where
16-
def = defExpr.getATypeNameUse() and
17-
E = def.getDeclaration() and
15+
def = defLine.getATypeNameUse() and
16+
var = def.getDeclaration() and
1817
use = useExpr.getArrayBase() and
19-
E = use.getTarget() and
20-
useExpr.getArrayOffset().getType() instanceof UInt16_t and
21-
defExpr.getArraySize() <= 256
22-
select useExpr, "Using a UInt16_t to acess the array $@ of size " + defExpr.getArraySize() + ".", E,
23-
E.getName()
18+
var = use.getTarget() and (
19+
(useExpr.getArrayOffset().getType() instanceof UInt16_t and
20+
defLine.getArraySize() <= 256) or
21+
(useExpr.getArrayOffset().getType() instanceof UInt32_t and
22+
defLine.getArraySize() <= 900) or
23+
(useExpr.getArrayOffset().getType() instanceof UInt64_t and
24+
defLine.getArraySize() <= 1000)
25+
)
26+
select useExpr, "Using a " + useExpr.getArrayOffset().getType() +" to acess the array $@ of size " + defLine.getArraySize() + ".", var,
27+
var.getName()

0 commit comments

Comments
 (0)