Skip to content

Commit f01737a

Browse files
authored
Fixing BasicIntTypes to allow C Standard Integers and 'bool'
The purpose of this check is to ensure that all integral types used by the code point to some fixed size type (e.g. an unsigned 8-bit integer). However; the previous implementation only allowed JPL style typedefs (i.e. U8) and ignored C standard integer types (i.e. uint8_t). This causes the query to false-positive when a typedef resolves to a C standard int type. 'bool' has also be allowed as part of the exclusions list as it represents distinct values 'true' and 'false' in C++ code.
1 parent 269f9fa commit f01737a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cpp/ql/src/JPL_C/LOC-3/Rule 17/BasicIntTypes.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import cpp
1313

1414
predicate allowedTypedefs(TypedefType t) {
15-
t.getName() = ["I64", "U64", "I32", "U32", "I16", "U16", "I8", "U8", "F64", "F32"]
15+
t.getName() = ["I64", "U64", "I32", "U32", "I16", "U16", "I8", "U8", "F64", "F32",
16+
"int64_t", "uint64_t", "int32_t", "uint32_t", "int16_t", "uint16_t", "int8_t", "uint8_t"]
1617
}
1718

1819
/**
@@ -38,8 +39,8 @@ Type getAUsedType(Type t) {
3839
}
3940

4041
predicate problematic(IntegralType t) {
41-
// List any exceptions that should be allowed.
42-
any()
42+
// 'bool' is allowed as it represents a 'true' or 'false' value
43+
t.getName() != ["bool"]
4344
}
4445

4546
from Declaration d, Type usedType
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: majorAnalysis
3+
---
4+
* The query "Basic Integral Types" in JPL_C has been updated to allow C standard integer types (uint8_t etc.) and 'bool'.

0 commit comments

Comments
 (0)