Skip to content

Commit

Permalink
[analyzer] pr34779: CStringChecker: Accept non-standard headers.
Browse files Browse the repository at this point in the history
Do not crash when trying to define and call a non-standard
strcpy(unsigned char *, unsigned char *) during analysis.

At the same time, do not try to actually evaluate the call.

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

llvm-svn: 317565
  • Loading branch information
haoNoQ committed Nov 7, 2017
1 parent 603c645 commit 0b5b1f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
Expand Up @@ -289,8 +289,8 @@ ProgramStateRef CStringChecker::CheckLocation(CheckerContext &C,
if (!ER)
return state;

assert(ER->getValueType() == C.getASTContext().CharTy &&
"CheckLocation should only be called with char* ElementRegions");
if (ER->getValueType() != C.getASTContext().CharTy)
return state;

// Get the size of the array.
const SubRegion *superReg = cast<SubRegion>(ER->getSuperRegion());
Expand Down Expand Up @@ -874,6 +874,8 @@ bool CStringChecker::IsFirstBufInBound(CheckerContext &C,
if (!ER)
return true; // cf top comment.

// FIXME: Does this crash when a non-standard definition
// of a library function is encountered?
assert(ER->getValueType() == C.getASTContext().CharTy &&
"IsFirstBufInBound should only be called with char* ElementRegions");

Expand Down
10 changes: 10 additions & 0 deletions clang/test/Analysis/string-with-signedness.c
@@ -0,0 +1,10 @@
// RUN: %clang_analyze_cc1 -Wno-incompatible-library-redeclaration -analyzer-checker=core,unix.cstring,alpha.unix.cstring -verify %s

// expected-no-diagnostics

void *strcpy(unsigned char *, unsigned char *);

unsigned char a, b;
void testUnsignedStrcpy() {
strcpy(&a, &b);
}

0 comments on commit 0b5b1f1

Please sign in to comment.