Lines Matching refs:Result
45 static const Expr *getDestCapacityExpr(const MatchFinder::MatchResult &Result) { in getDestCapacityExpr() argument
46 if (const auto *DestMalloc = Result.Nodes.getNodeAs<Expr>(DestMallocExprName)) in getDestCapacityExpr()
50 Result.Nodes.getNodeAs<VariableArrayType>(DestArrayTyName)) in getDestCapacityExpr()
53 if (const auto *DestVD = Result.Nodes.getNodeAs<VarDecl>(DestVarDeclName)) in getDestCapacityExpr()
64 const MatchFinder::MatchResult &Result) { in getLength() argument
75 if (LengthInit->EvaluateAsInt(Length, *Result.Context)) in getLength()
96 static int getDestCapacity(const MatchFinder::MatchResult &Result) { in getDestCapacity() argument
97 if (const auto *DestCapacityExpr = getDestCapacityExpr(Result)) in getDestCapacity()
98 return getLength(DestCapacityExpr, Result); in getDestCapacity()
104 static const CallExpr *getStrlenExpr(const MatchFinder::MatchResult &Result) { in getStrlenExpr() argument
106 Result.Nodes.getNodeAs<CallExpr>(WrongLengthExprName)) in getStrlenExpr()
118 static int getGivenLength(const MatchFinder::MatchResult &Result) { in getGivenLength() argument
119 if (Result.Nodes.getNodeAs<Expr>(UnknownLengthName)) in getGivenLength()
123 getLength(Result.Nodes.getNodeAs<Expr>(WrongLengthExprName), Result)) in getGivenLength()
127 getLength(Result.Nodes.getNodeAs<Expr>(LengthExprName), Result)) in getGivenLength()
131 if (const CallExpr *StrlenCE = getStrlenExpr(Result)) in getGivenLength()
133 if (int ArgLength = getLength(Arg, Result)) in getGivenLength()
141 const MatchFinder::MatchResult &Result) { in exprToStr() argument
147 *Result.SourceManager, Result.Context->getLangOpts(), nullptr); in exprToStr()
152 const MatchFinder::MatchResult &Result) { in exprLocEnd() argument
153 return Lexer::getLocForEndOfToken(E->getEndLoc(), 0, *Result.SourceManager, in exprLocEnd()
154 Result.Context->getLangOpts()); in exprLocEnd()
164 static bool isInjectUL(const MatchFinder::MatchResult &Result) { in isInjectUL() argument
165 return getGivenLength(Result) == std::numeric_limits<int>::max(); in isInjectUL()
169 static bool isKnownDest(const MatchFinder::MatchResult &Result) { in isKnownDest() argument
170 return !Result.Nodes.getNodeAs<Expr>(UnknownDestName); in isKnownDest()
175 static bool isDestBasedOnGivenLength(const MatchFinder::MatchResult &Result) { in isDestBasedOnGivenLength() argument
177 exprToStr(getDestCapacityExpr(Result), Result).trim(); in isDestBasedOnGivenLength()
179 exprToStr(Result.Nodes.getNodeAs<Expr>(LengthExprName), Result).trim(); in isDestBasedOnGivenLength()
186 static bool isDestAndSrcEquals(const MatchFinder::MatchResult &Result) { in isDestAndSrcEquals() argument
187 if (const auto *DestDRE = Result.Nodes.getNodeAs<DeclRefExpr>(DestExprName)) in isDestAndSrcEquals()
188 if (const auto *SrcDRE = Result.Nodes.getNodeAs<DeclRefExpr>(SrcExprName)) in isDestAndSrcEquals()
196 static bool isStringDataAndLength(const MatchFinder::MatchResult &Result) { in isStringDataAndLength() argument
198 Result.Nodes.getNodeAs<CXXMemberCallExpr>(DestExprName); in isStringDataAndLength()
199 const auto *SrcExpr = Result.Nodes.getNodeAs<CXXMemberCallExpr>(SrcExprName); in isStringDataAndLength()
201 Result.Nodes.getNodeAs<CXXMemberCallExpr>(WrongLengthExprName); in isStringDataAndLength()
221 isGivenLengthEqualToSrcLength(const MatchFinder::MatchResult &Result) { in isGivenLengthEqualToSrcLength() argument
222 if (Result.Nodes.getNodeAs<Expr>(UnknownLengthName)) in isGivenLengthEqualToSrcLength()
225 if (isStringDataAndLength(Result)) in isGivenLengthEqualToSrcLength()
228 int GivenLength = getGivenLength(Result); in isGivenLengthEqualToSrcLength()
229 int SrcLength = getLength(Result.Nodes.getNodeAs<Expr>(SrcExprName), Result); in isGivenLengthEqualToSrcLength()
234 if (const auto *LengthExpr = Result.Nodes.getNodeAs<Expr>(LengthExprName)) in isGivenLengthEqualToSrcLength()
239 if (const CallExpr *StrlenCE = getStrlenExpr(Result)) in isGivenLengthEqualToSrcLength()
242 if (const auto *SrcVD = Result.Nodes.getNodeAs<VarDecl>(SrcVarDeclName)) in isGivenLengthEqualToSrcLength()
248 static bool isCorrectGivenLength(const MatchFinder::MatchResult &Result) { in isCorrectGivenLength() argument
249 if (Result.Nodes.getNodeAs<Expr>(UnknownLengthName)) in isCorrectGivenLength()
252 return !isGivenLengthEqualToSrcLength(Result); in isCorrectGivenLength()
258 static bool isDestCapacityOverflows(const MatchFinder::MatchResult &Result) { in isDestCapacityOverflows() argument
259 if (!isKnownDest(Result)) in isDestCapacityOverflows()
262 const Expr *DestCapacityExpr = getDestCapacityExpr(Result); in isDestCapacityOverflows()
263 int DestCapacity = getLength(DestCapacityExpr, Result); in isDestCapacityOverflows()
264 int GivenLength = getGivenLength(Result); in isDestCapacityOverflows()
267 return isGivenLengthEqualToSrcLength(Result) && DestCapacity == GivenLength; in isDestCapacityOverflows()
271 StringRef DestCapacityExprStr = exprToStr(DestCapacityExpr, Result); in isDestCapacityOverflows()
279 isFixedGivenLengthAndUnknownSrc(const MatchFinder::MatchResult &Result) { in isFixedGivenLengthAndUnknownSrc() argument
280 if (Result.Nodes.getNodeAs<IntegerLiteral>(WrongLengthExprName)) in isFixedGivenLengthAndUnknownSrc()
281 return !getLength(Result.Nodes.getNodeAs<Expr>(SrcExprName), Result); in isFixedGivenLengthAndUnknownSrc()
293 const MatchFinder::MatchResult &Result, in lengthExprHandle() argument
299 StringRef LengthExprStr = exprToStr(LengthExpr, Result); in lengthExprHandle()
313 ? (isInjectUL(Result) ? 1UL : 1) in lengthExprHandle()
318 (Twine(NewLength) + (isInjectUL(Result) ? "UL" : "")).str()); in lengthExprHandle()
359 if (isInjectUL(Result)) in lengthExprHandle()
362 Diag << FixItHint::CreateInsertion(exprLocEnd(LengthExpr, Result), Injection); in lengthExprHandle()
366 const MatchFinder::MatchResult &Result, in lengthArgHandle() argument
368 const auto *LengthExpr = Result.Nodes.getNodeAs<Expr>(LengthExprName); in lengthArgHandle()
369 lengthExprHandle(LengthExpr, LengthHandle, Result, Diag); in lengthArgHandle()
373 const MatchFinder::MatchResult &Result, in lengthArgPosHandle() argument
375 const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName); in lengthArgPosHandle()
376 lengthExprHandle(FunctionExpr->getArg(ArgPos), LengthHandle, Result, Diag); in lengthArgPosHandle()
381 static bool isDestExprFix(const MatchFinder::MatchResult &Result, in isDestExprFix() argument
383 const auto *Dest = Result.Nodes.getNodeAs<Expr>(DestExprName); in isDestExprFix()
398 static bool isDestCapacityFix(const MatchFinder::MatchResult &Result, in isDestCapacityFix() argument
400 bool IsOverflows = isDestCapacityOverflows(Result); in isDestCapacityFix()
402 if (const Expr *CapacityExpr = getDestCapacityExpr(Result)) in isDestCapacityFix()
403 lengthExprHandle(CapacityExpr, LengthHandleKind::Increase, Result, Diag); in isDestCapacityFix()
408 static void removeArg(int ArgPos, const MatchFinder::MatchResult &Result, in removeArg() argument
414 const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName); in removeArg()
418 SourceRange(exprLocEnd(LHSArg, Result), in removeArg()
419 exprLocEnd(ArgToRemove, Result).getLocWithOffset(-1))); in removeArg()
424 const MatchFinder::MatchResult &Result, in renameFunc() argument
426 const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName); in renameFunc()
439 const MatchFinder::MatchResult &Result, in renameMemcpy() argument
445 renameFunc(NewFuncName, Result, Diag); in renameMemcpy()
449 const MatchFinder::MatchResult &Result, in insertDestCapacityArg() argument
451 const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName); in insertDestCapacityArg()
454 if (int DestLength = getDestCapacity(Result)) { in insertDestCapacityArg()
458 (Twine(exprToStr(getDestCapacityExpr(Result), Result)) + in insertDestCapacityArg()
459 (IsOverflows ? (!isInjectUL(Result) ? " + 1" : " + 1UL") : "")) in insertDestCapacityArg()
470 const MatchFinder::MatchResult &Result, in insertNullTerminatorExpr() argument
472 const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName); in insertNullTerminatorExpr()
473 int FuncLocStartColumn = Result.SourceManager->getPresumedColumnNumber( in insertNullTerminatorExpr()
479 CharSourceRange::getCharRange(SpaceRange), *Result.SourceManager, in insertNullTerminatorExpr()
480 Result.Context->getLangOpts(), nullptr); in insertNullTerminatorExpr()
485 exprToStr(Result.Nodes.getNodeAs<Expr>(DestExprName), Result) + "[" + in insertNullTerminatorExpr()
486 exprToStr(Result.Nodes.getNodeAs<Expr>(LengthExprName), Result) + in insertNullTerminatorExpr()
491 exprLocEnd(FunctionExpr, Result).getLocWithOffset(1), in insertNullTerminatorExpr()
793 const MatchFinder::MatchResult &Result) { in check() argument
794 const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName); in check()
826 memoryHandlerFunctionFix(Name, Result); in check()
828 strerror_sFix(Result); in check()
830 ncmpFix(Name, Result); in check()
832 xfrmFix(Name, Result); in check()
836 StringRef Name, const MatchFinder::MatchResult &Result) { in memoryHandlerFunctionFix() argument
837 if (isCorrectGivenLength(Result)) in memoryHandlerFunctionFix()
841 memchrFix(Name, Result); in memoryHandlerFunctionFix()
846 (isDestAndSrcEquals(Result) || isFixedGivenLengthAndUnknownSrc(Result))) in memoryHandlerFunctionFix()
850 diag(Result.Nodes.getNodeAs<CallExpr>(FunctionExprName)->getBeginLoc(), in memoryHandlerFunctionFix()
855 memcpyFix(Name, Result, Diag); in memoryHandlerFunctionFix()
857 memcpy_sFix(Name, Result, Diag); in memoryHandlerFunctionFix()
859 memmoveFix(Name, Result, Diag); in memoryHandlerFunctionFix()
861 isDestCapacityFix(Result, Diag); in memoryHandlerFunctionFix()
862 lengthArgHandle(LengthHandleKind::Increase, Result, Diag); in memoryHandlerFunctionFix()
867 StringRef Name, const MatchFinder::MatchResult &Result, in memcpyFix() argument
869 bool IsOverflows = isDestCapacityFix(Result, Diag); in memcpyFix()
870 bool IsDestFixed = isDestExprFix(Result, Diag); in memcpyFix()
873 isGivenLengthEqualToSrcLength(Result) || isDestBasedOnGivenLength(Result); in memcpyFix()
875 bool IsSafe = UseSafeFunctions && IsOverflows && isKnownDest(Result) && in memcpyFix()
876 !isDestBasedOnGivenLength(Result); in memcpyFix()
880 Result.Nodes.getNodeAs<ArrayType>(DestArrayTyName) && !IsDestFixed; in memcpyFix()
882 renameMemcpy(Name, IsCopy, IsSafe, Result, Diag); in memcpyFix()
885 insertDestCapacityArg(IsOverflows, Name, Result, Diag); in memcpyFix()
888 removeArg(2, Result, Diag); in memcpyFix()
891 insertNullTerminatorExpr(Name, Result, Diag); in memcpyFix()
895 StringRef Name, const MatchFinder::MatchResult &Result, in memcpy_sFix() argument
897 bool IsOverflows = isDestCapacityFix(Result, Diag); in memcpy_sFix()
898 bool IsDestFixed = isDestExprFix(Result, Diag); in memcpy_sFix()
901 Result.Nodes.getNodeAs<ArrayType>(DestArrayTyName) && in memcpy_sFix()
903 bool IsCopy = isGivenLengthEqualToSrcLength(Result); in memcpy_sFix()
906 renameMemcpy(Name, IsCopy, IsSafe, Result, Diag); in memcpy_sFix()
909 removeArg(1, Result, Diag); in memcpy_sFix()
910 else if (IsOverflows && isKnownDest(Result)) in memcpy_sFix()
911 lengthArgPosHandle(1, LengthHandleKind::Increase, Result, Diag); in memcpy_sFix()
914 removeArg(3, Result, Diag); in memcpy_sFix()
917 insertNullTerminatorExpr(Name, Result, Diag); in memcpy_sFix()
921 StringRef Name, const MatchFinder::MatchResult &Result) { in memchrFix() argument
922 const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName); in memchrFix()
930 if (const auto *CastExpr = Result.Nodes.getNodeAs<Expr>(CastExprName)) { in memchrFix()
938 renameFunc(NewFuncName, Result, Diag); in memchrFix()
939 removeArg(2, Result, Diag); in memchrFix()
943 StringRef Name, const MatchFinder::MatchResult &Result, in memmoveFix() argument
945 bool IsOverflows = isDestCapacityFix(Result, Diag); in memmoveFix()
947 if (UseSafeFunctions && isKnownDest(Result)) { in memmoveFix()
948 renameFunc((Name[0] != 'w') ? "memmove_s" : "wmemmove_s", Result, Diag); in memmoveFix()
949 insertDestCapacityArg(IsOverflows, Name, Result, Diag); in memmoveFix()
952 lengthArgHandle(LengthHandleKind::Increase, Result, Diag); in memmoveFix()
956 const MatchFinder::MatchResult &Result) { in strerror_sFix() argument
958 diag(Result.Nodes.getNodeAs<CallExpr>(FunctionExprName)->getBeginLoc(), in strerror_sFix()
962 isDestCapacityFix(Result, Diag); in strerror_sFix()
963 lengthArgHandle(LengthHandleKind::Increase, Result, Diag); in strerror_sFix()
967 StringRef Name, const MatchFinder::MatchResult &Result) { in ncmpFix() argument
968 const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName); in ncmpFix()
973 if (const CallExpr *StrlenExpr = getStrlenExpr(Result)) { in ncmpFix()
975 StringRef FirstExprStr = exprToStr(FirstArgExpr, Result).trim(); in ncmpFix()
976 StringRef SecondExprStr = exprToStr(SecondArgExpr, Result).trim(); in ncmpFix()
977 StringRef LengthArgStr = exprToStr(LengthExprArg, Result).trim(); in ncmpFix()
982 getLength(Result.Nodes.getNodeAs<Expr>(SrcExprName), Result); in ncmpFix()
983 int GivenLength = getGivenLength(Result); in ncmpFix()
988 if (!IsLengthTooLong && !isStringDataAndLength(Result)) in ncmpFix()
995 lengthArgHandle(LengthHandleKind::Decrease, Result, Diag); in ncmpFix()
999 StringRef Name, const MatchFinder::MatchResult &Result) { in xfrmFix() argument
1000 if (!isDestCapacityOverflows(Result)) in xfrmFix()
1004 diag(Result.Nodes.getNodeAs<CallExpr>(FunctionExprName)->getBeginLoc(), in xfrmFix()
1008 isDestCapacityFix(Result, Diag); in xfrmFix()
1009 lengthArgHandle(LengthHandleKind::Increase, Result, Diag); in xfrmFix()