From fececcbc3890955fd46f92036e9cb6ee7d0a60f4 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Wed, 10 Apr 2013 22:06:29 +0000 Subject: [PATCH] [analyzer] Fix a crash in SyntaxCString checker when given a custom strncat. Fixes PR13476 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179228 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp | 2 ++ test/Analysis/cstring-syntax-cxx.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp b/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp index 3a57a56aea..92c0eef3e8 100644 --- a/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp @@ -101,6 +101,8 @@ public: // - strncat(dst, src, sizeof(dst) - 1); // - strncat(dst, src, sizeof(dst)); bool WalkAST::containsBadStrncatPattern(const CallExpr *CE) { + if (CE->getNumArgs() != 3) + return false; const Expr *DstArg = CE->getArg(0); const Expr *SrcArg = CE->getArg(1); const Expr *LenArg = CE->getArg(2); diff --git a/test/Analysis/cstring-syntax-cxx.cpp b/test/Analysis/cstring-syntax-cxx.cpp index bae3d0a164..39c978ab60 100644 --- a/test/Analysis/cstring-syntax-cxx.cpp +++ b/test/Analysis/cstring-syntax-cxx.cpp @@ -15,3 +15,8 @@ void test(X a, X b) { X c = a + b; } +// Ensure we don't crash on custom-defined strncat. +char strncat (); +int main () { + return strncat (); +} \ No newline at end of file -- 2.40.0