Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ static bool evenFlexibleArraySize(ASTContext &Ctx, CharUnits RegionSize,
assert(Last && "empty structs should already be handled");

const Type *ElemType = Last->getType()->getArrayElementTypeNoTypeQual();
if (!ElemType)
return false;
CharUnits FlexSize;
if (const ConstantArrayType *ArrayTy =
Ctx.getAsConstantArrayType(Last->getType())) {
Expand Down
25 changes: 25 additions & 0 deletions clang/test/Analysis/castsize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang_analyze_cc1 -verify %s \
// RUN: -analyzer-checker=core,unix.Malloc,alpha.core.CastSize

void *malloc(unsigned long);

struct s1 {
int a;
char x[];
};

struct s2 {
int a[100];
char x[];
};

union u {
struct s1 a;
struct s2 b;
};

static union u *test() {
union u *req;
req = malloc(5); // expected-warning{{Cast a region whose size is not a multiple of the destination type size}}
return req;
}
Loading