mirror of
https://github.com/github/codeql.git
synced 2025-12-23 04:06:37 +01:00
C/C++ : change Variable and ArrayType name + Add detection for Uint 32 and 64
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
</overview>
|
</overview>
|
||||||
|
|
||||||
<recommendation>
|
<recommendation>
|
||||||
<p>Use a Uint8 instead</p>
|
<p>Use a int with a lower bit size instead. For instance in this example use a 8 bit int.</p>
|
||||||
</recommendation>
|
</recommendation>
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
|
|||||||
@@ -8,16 +8,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import cpp
|
import cpp
|
||||||
import semmle.code.cpp.controlflow.SSA
|
|
||||||
|
|
||||||
from
|
from
|
||||||
Variable E, ArrayExpr useExpr, ArrayType defExpr, VariableDeclarationEntry def, VariableAccess use
|
Variable var, ArrayExpr useExpr, VariableDeclarationEntry def, ArrayType defLine, VariableAccess use
|
||||||
where
|
where
|
||||||
def = defExpr.getATypeNameUse() and
|
def = defLine.getATypeNameUse() and
|
||||||
E = def.getDeclaration() and
|
var = def.getDeclaration() and
|
||||||
use = useExpr.getArrayBase() and
|
use = useExpr.getArrayBase() and
|
||||||
E = use.getTarget() and
|
var = use.getTarget() and (
|
||||||
useExpr.getArrayOffset().getType() instanceof UInt16_t and
|
(useExpr.getArrayOffset().getType() instanceof UInt16_t and
|
||||||
defExpr.getArraySize() <= 256
|
defLine.getArraySize() <= 256) or
|
||||||
select useExpr, "Using a UInt16_t to acess the array $@ of size " + defExpr.getArraySize() + ".", E,
|
(useExpr.getArrayOffset().getType() instanceof UInt32_t and
|
||||||
E.getName()
|
defLine.getArraySize() <= 900) or
|
||||||
|
(useExpr.getArrayOffset().getType() instanceof UInt64_t and
|
||||||
|
defLine.getArraySize() <= 1000)
|
||||||
|
)
|
||||||
|
select useExpr, "Using a " + useExpr.getArrayOffset().getType() +" to acess the array $@ of size " + defLine.getArraySize() + ".", var,
|
||||||
|
var.getName()
|
||||||
|
|||||||
Reference in New Issue
Block a user