[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 llvm-svn: 331401
This commit is contained in:
parent
41695f8e73
commit
1aaf402530
|
@ -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(CheckerContext &C, const CallExpr *CE) const {
|
|||
/* 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(CheckerContext &C, const CallExpr *CE) const {
|
|||
/* 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(CheckerContext &C, const CallExpr *CE,
|
|||
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 CallExpr *CE, CheckerContext &C) const {
|
|||
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"))
|
||||
|
|
Loading…
Reference in New Issue