forked from OSchip/llvm-project
[analyzer] [PR39792] false positive on strcpy targeting struct members
Patch by Pierre van Houtryve. Differential Revision: https://reviews.llvm.org/D55226 llvm-svn: 351097
This commit is contained in:
parent
704913f562
commit
e2a8eec457
|
@ -651,8 +651,8 @@ void WalkAST::checkCall_strcpy(const CallExpr *CE, const FunctionDecl *FD) {
|
|||
|
||||
const auto *Target = CE->getArg(0)->IgnoreImpCasts(),
|
||||
*Source = CE->getArg(1)->IgnoreImpCasts();
|
||||
if (const auto *DeclRef = dyn_cast<DeclRefExpr>(Target))
|
||||
if (const auto *Array = dyn_cast<ConstantArrayType>(DeclRef->getType())) {
|
||||
|
||||
if (const auto *Array = dyn_cast<ConstantArrayType>(Target->getType())) {
|
||||
uint64_t ArraySize = BR.getContext().getTypeSize(Array) / 8;
|
||||
if (const auto *String = dyn_cast<StringLiteral>(Source)) {
|
||||
if (ArraySize >= String->getLength() + 1)
|
||||
|
|
|
@ -177,6 +177,11 @@ void test_strcpy_safe() {
|
|||
strcpy(x, "abcd");
|
||||
}
|
||||
|
||||
void test_strcpy_safe_2() {
|
||||
struct {char s1[100];} s;
|
||||
strcpy(s.s1, "hello");
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===
|
||||
// strcat()
|
||||
//===----------------------------------------------------------------------===
|
||||
|
|
Loading…
Reference in New Issue