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:
M Starch
2025-03-11 14:56:57 -07:00
committed by GitHub
parent 269f9fa7c9
commit f01737a4c0
2 changed files with 8 additions and 3 deletions

View File

@@ -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

View 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'.