mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
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.
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
import cpp
|
||||
|
||||
predicate allowedTypedefs(TypedefType t) {
|
||||
t.getName() = ["I64", "U64", "I32", "U32", "I16", "U16", "I8", "U8", "F64", "F32"]
|
||||
t.getName() = ["I64", "U64", "I32", "U32", "I16", "U16", "I8", "U8", "F64", "F32",
|
||||
"int64_t", "uint64_t", "int32_t", "uint32_t", "int16_t", "uint16_t", "int8_t", "uint8_t"]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,8 +39,8 @@ Type getAUsedType(Type t) {
|
||||
}
|
||||
|
||||
predicate problematic(IntegralType t) {
|
||||
// List any exceptions that should be allowed.
|
||||
any()
|
||||
// 'bool' is allowed as it represents a 'true' or 'false' value
|
||||
t.getName() != ["bool"]
|
||||
}
|
||||
|
||||
from Declaration d, Type usedType
|
||||
|
||||
4
cpp/ql/src/change-notes/2025-03-11-basic-int-types.md
Normal file
4
cpp/ql/src/change-notes/2025-03-11-basic-int-types.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: majorAnalysis
|
||||
---
|
||||
* The query "Basic Integral Types" in JPL_C has been updated to allow C standard integer types (uint8_t etc.) and 'bool'.
|
||||
Reference in New Issue
Block a user