r331401 - [analyzer] Revert r331096 "CStringChecker: Add support for BSD strlcpy()...".

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Wed May 2 13:33:17 PDT 2018


Author: dergachev
Date: Wed May  2 13:33:17 2018
New Revision: 331401

URL: http://llvm.org/viewvc/llvm-project?rev=331401&view=rev
Log:
[analyzer] Revert r331096 "CStringChecker: Add support for BSD strlcpy()...".

The return values of the newly supported functions were not handled correctly:
strlcpy()/strlcat() return string sizes rather than pointers.

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

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=331401&r1=331400&r2=331401&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Wed May  2 13:33:17 2018
@@ -97,17 +97,14 @@ public:
   void evalStrcpy(CheckerContext &C, const CallExpr *CE) const;
   void evalStrncpy(CheckerContext &C, const CallExpr *CE) const;
   void evalStpcpy(CheckerContext &C, const CallExpr *CE) const;
-  void evalStrlcpy(CheckerContext &C, const CallExpr *CE) const;
   void evalStrcpyCommon(CheckerContext &C,
                         const CallExpr *CE,
                         bool returnEnd,
                         bool isBounded,
-                        bool isAppending,
-                        bool canOverlap = false) const;
+                        bool isAppending) const;
 
   void evalStrcat(CheckerContext &C, const CallExpr *CE) const;
   void evalStrncat(CheckerContext &C, const CallExpr *CE) const;
-  void evalStrlcat(CheckerContext &C, const CallExpr *CE) const;
 
   void evalStrcmp(CheckerContext &C, const CallExpr *CE) const;
   void evalStrncmp(CheckerContext &C, const CallExpr *CE) const;
@@ -1396,18 +1393,6 @@ void CStringChecker::evalStpcpy(CheckerC
                    /* isAppending = */ false);
 }
 
-void CStringChecker::evalStrlcpy(CheckerContext &C, const CallExpr *CE) const {
-  if (CE->getNumArgs() < 3)
-    return;
-
-  // char *strlcpy(char *dst, const char *src, size_t n);
-  evalStrcpyCommon(C, CE,
-                   /* returnEnd = */ true,
-                   /* isBounded = */ true,
-                   /* isAppending = */ false,
-                   /* canOverlap = */ true);
-}
-
 void CStringChecker::evalStrcat(CheckerContext &C, const CallExpr *CE) const {
   if (CE->getNumArgs() < 2)
     return;
@@ -1430,21 +1415,9 @@ void CStringChecker::evalStrncat(Checker
                    /* isAppending = */ true);
 }
 
-void CStringChecker::evalStrlcat(CheckerContext &C, const CallExpr *CE) const {
-  if (CE->getNumArgs() < 3)
-    return;
-
-  //char *strlcat(char *s1, const char *s2, size_t n);
-  evalStrcpyCommon(C, CE,
-                   /* returnEnd = */ false,
-                   /* isBounded = */ true,
-                   /* isAppending = */ true,
-                   /* canOverlap = */ true);
-}
-
 void CStringChecker::evalStrcpyCommon(CheckerContext &C, const CallExpr *CE,
                                       bool returnEnd, bool isBounded,
-                                      bool isAppending, bool canOverlap) const {
+                                      bool isAppending) const {
   CurrentFunctionDescription = "string copy function";
   ProgramStateRef state = C.getState();
   const LocationContext *LCtx = C.getLocationContext();
@@ -1482,12 +1455,6 @@ void CStringChecker::evalStrcpyCommon(Ch
   SVal maxLastElementIndex = UnknownVal();
   const char *boundWarning = nullptr;
 
-  if (canOverlap)
-    state = CheckOverlap(C, state, CE->getArg(2), Dst, srcExpr);
-
-  if (!state)
-    return;
-
   // If the function is strncpy, strncat, etc... it is bounded.
   if (isBounded) {
     // Get the max number of characters to copy.
@@ -2124,14 +2091,10 @@ bool CStringChecker::evalCall(const Call
     evalFunction =  &CStringChecker::evalStrncpy;
   else if (C.isCLibraryFunction(FDecl, "stpcpy"))
     evalFunction =  &CStringChecker::evalStpcpy;
-  else if (C.isCLibraryFunction(FDecl, "strlcpy"))
-    evalFunction =  &CStringChecker::evalStrlcpy;
   else if (C.isCLibraryFunction(FDecl, "strcat"))
     evalFunction =  &CStringChecker::evalStrcat;
   else if (C.isCLibraryFunction(FDecl, "strncat"))
     evalFunction =  &CStringChecker::evalStrncat;
-  else if (C.isCLibraryFunction(FDecl, "strlcat"))
-    evalFunction =  &CStringChecker::evalStrlcat;
   else if (C.isCLibraryFunction(FDecl, "strlen"))
     evalFunction =  &CStringChecker::evalstrLength;
   else if (C.isCLibraryFunction(FDecl, "strnlen"))




More information about the cfe-commits mailing list