[analyzer] CStringChecker fix for strlcpy when no bytes are copied to the dest buffer

Again, strlc* does not return a pointer so the zero size case doest not fit.

Reviewers: NoQ, george.karpenkov

Reviewed by: NoQ

Differential Revision: https://reviews.llvm.org/D47007

llvm-svn: 333060
This commit is contained in:
David Carlier 2018-05-23 04:38:25 +00:00
parent 5764db4e57
commit 3c90fcebd4
2 changed files with 10 additions and 1 deletions

View File

@ -1652,7 +1652,11 @@ void CStringChecker::evalStrcpyCommon(CheckerContext &C, const CallExpr *CE,
// If the size is known to be zero, we're done.
if (StateZeroSize && !StateNonZeroSize) {
StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, DstVal);
if (returnPtr) {
StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, DstVal);
} else {
StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, *lenValNL);
}
C.addTransition(StateZeroSize);
return;
}

View File

@ -38,3 +38,8 @@ void f6() {
size_t len = strlcat(buf, "defg", 4);
clang_analyzer_eval(len == 7); // expected-warning{{TRUE}}
}
int f7() {
char buf[8];
return strlcpy(buf, "1234567", 0); // no-crash
}