summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2017-11-07 10:51:15 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2017-11-07 10:51:15 +0000
commit0b5b1f14fd9a39e7a583ce2f2ef3afe08c39c6a3 (patch)
tree038917a55b003b76885d60e5258df68389ede214 /clang
parent603c6455d2ffbff096acb5f2902e3212885ef379 (diff)
downloadbcm5719-llvm-0b5b1f14fd9a39e7a583ce2f2ef3afe08c39c6a3.tar.gz
bcm5719-llvm-0b5b1f14fd9a39e7a583ce2f2ef3afe08c39c6a3.zip
[analyzer] pr34779: CStringChecker: Accept non-standard headers.
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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp6
-rw-r--r--clang/test/Analysis/string-with-signedness.c10
2 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 58218df2388..28ad7e9e507 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -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());
@@ -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");
diff --git a/clang/test/Analysis/string-with-signedness.c b/clang/test/Analysis/string-with-signedness.c
new file mode 100644
index 00000000000..1b00971a834
--- /dev/null
+++ b/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);
+}
OpenPOWER on IntegriCloud