Skip to content

Commit 0e09a33

Browse files
eupharinaresistor
authored andcommitted
[CHERI_CSA] AllocationChecker: suppress for flexible array
1 parent 5b04c96 commit 0e09a33

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/StaticAnalyzer/Checkers/CHERI/AllocationChecker.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,14 @@ bool relatedTypes(const Type *Ty1, const Type *Ty2) {
107107
bool reportForType(QualType Ty) {
108108
if (Ty->isVoidPointerType())
109109
return false;
110-
if (Ty->isPointerType() || Ty->isArrayType())
111-
return !Ty->getPointeeOrArrayElementType()->isCharType();
110+
if (Ty->isPointerType() || Ty->isArrayType()) {
111+
const Type *PTy = Ty->getPointeeOrArrayElementType();
112+
if (PTy->isCharType())
113+
return false;
114+
if (PTy->isStructureTypeWithFlexibleArrayMember())
115+
return false;
116+
return true;
117+
}
112118
return false;
113119
}
114120

clang/test/Analysis/Checkers/CHERI/allocation.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,14 @@ struct S2 * first_field(void *p, int n1) {
5151
struct S2 *p2 = (struct S2 *)(p3+n1); // no warn
5252
return p2;
5353
}
54+
55+
struct S4 {
56+
long len;
57+
int buf[];
58+
};
59+
60+
int* flex_array(int len) {
61+
struct S4 *p = malloc(sizeof(struct S4) + len*sizeof(int));
62+
int *pB = (int*)(p + 1); // no warn
63+
return pB;
64+
}

0 commit comments

Comments
 (0)