[cfe-commits] r88779 - in /cfe/trunk: include/clang/Analysis/PathSensitive/ lib/Analysis/

Ted Kremenek kremenek at apple.com
Sat Nov 14 09:04:37 PST 2009


Awesome.  Thanks!

On Nov 14, 2009, at 4:08 AM, Benjamin Kramer wrote:

> Author: d0k
> Date: Sat Nov 14 06:08:24 2009
> New Revision: 88779
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=88779&view=rev
> Log:
> Change *BugReport constructors to take StringRefs.
> 
> - Eliminates many calls to std::string.c_str()
> - Fixes an invalid read in ReturnStackAddressChecker due to an unsafe call to
>  StringRef.data() which doesn't guarantee null-termination.
> 
> Modified:
>    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
>    cfe/trunk/lib/Analysis/ArrayBoundChecker.cpp
>    cfe/trunk/lib/Analysis/BadCallChecker.cpp
>    cfe/trunk/lib/Analysis/CallGraph.cpp
>    cfe/trunk/lib/Analysis/CastToStructChecker.cpp
>    cfe/trunk/lib/Analysis/DereferenceChecker.cpp
>    cfe/trunk/lib/Analysis/DivZeroChecker.cpp
>    cfe/trunk/lib/Analysis/FixedAddressChecker.cpp
>    cfe/trunk/lib/Analysis/MallocChecker.cpp
>    cfe/trunk/lib/Analysis/PointerArithChecker.cpp
>    cfe/trunk/lib/Analysis/PointerSubChecker.cpp
>    cfe/trunk/lib/Analysis/ReturnPointerRangeChecker.cpp
>    cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp
>    cfe/trunk/lib/Analysis/ReturnUndefChecker.cpp
>    cfe/trunk/lib/Analysis/UndefinedArgChecker.cpp
>    cfe/trunk/lib/Analysis/UndefinedArraySubscriptChecker.cpp
>    cfe/trunk/lib/Analysis/UndefinedAssignmentChecker.cpp
>    cfe/trunk/lib/Analysis/VLASizeChecker.cpp
> 
> Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
> +++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Sat Nov 14 06:08:24 2009
> @@ -81,10 +81,10 @@
>             getOriginalNode(const ExplodedNode* N) = 0;
>   };
> 
> -  BugReport(BugType& bt, const char* desc, const ExplodedNode *n)
> +  BugReport(BugType& bt, llvm::StringRef desc, const ExplodedNode *n)
>     : BT(bt), Description(desc), EndNode(n) {}
> 
> -  BugReport(BugType& bt, const char* shortDesc, const char* desc,
> +  BugReport(BugType& bt, llvm::StringRef shortDesc, llvm::StringRef desc,
>             const ExplodedNode *n)
>   : BT(bt), ShortDescription(shortDesc), Description(desc), EndNode(n) {}
> 
> @@ -193,11 +193,11 @@
> class RangedBugReport : public BugReport {
>   std::vector<SourceRange> Ranges;
> public:
> -  RangedBugReport(BugType& D, const char* description, ExplodedNode *n)
> +  RangedBugReport(BugType& D, llvm::StringRef description, ExplodedNode *n)
>     : BugReport(D, description, n) {}
> 
> -  RangedBugReport(BugType& D, const char *shortDescription,
> -                  const char *description, ExplodedNode *n)
> +  RangedBugReport(BugType& D, llvm::StringRef shortDescription,
> +                  llvm::StringRef description, ExplodedNode *n)
>   : BugReport(D, shortDescription, description, n) {}
> 
>   ~RangedBugReport();
> @@ -229,11 +229,11 @@
>   Creators creators;
> 
> public:
> -  EnhancedBugReport(BugType& D, const char* description, ExplodedNode *n)
> +  EnhancedBugReport(BugType& D, llvm::StringRef description, ExplodedNode *n)
>    : RangedBugReport(D, description, n) {}
> 
> -  EnhancedBugReport(BugType& D, const char *shortDescription,
> -                  const char *description, ExplodedNode *n)
> +  EnhancedBugReport(BugType& D, llvm::StringRef shortDescription,
> +                   llvm::StringRef description, ExplodedNode *n)
>     : RangedBugReport(D, shortDescription, description, n) {}
> 
>   ~EnhancedBugReport() {}
> 
> Modified: cfe/trunk/lib/Analysis/ArrayBoundChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ArrayBoundChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/ArrayBoundChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/ArrayBoundChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -77,7 +77,7 @@
> 
>     // Generate a report for this bug.
>     RangedBugReport *report = 
> -      new RangedBugReport(*BT, BT->getDescription().c_str(), N);
> +      new RangedBugReport(*BT, BT->getDescription(), N);
> 
>     report->addRange(S->getSourceRange());
> 
> 
> Modified: cfe/trunk/lib/Analysis/BadCallChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BadCallChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/BadCallChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/BadCallChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -46,7 +46,7 @@
>                 "Called function pointer is a null or undefined pointer value");
> 
>       EnhancedBugReport *R =
> -        new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);
> +        new EnhancedBugReport(*BT, BT->getDescription(), N);
> 
>       R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
>                            bugreporter::GetCalleeExpr(N));
> 
> Modified: cfe/trunk/lib/Analysis/CallGraph.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CallGraph.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/CallGraph.cpp (original)
> +++ cfe/trunk/lib/Analysis/CallGraph.cpp Sat Nov 14 06:08:24 2009
> @@ -117,7 +117,7 @@
>          << " calls:\n";
>       for (CallGraphNode::iterator CI = I->second->begin(),
>              CE = I->second->end(); CI != CE; ++CI) {
> -        os << "    " << CI->second->getName().c_str();
> +        os << "    " << CI->second->getName();
>       }
>       os << '\n';
>     }
> 
> Modified: cfe/trunk/lib/Analysis/CastToStructChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CastToStructChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/CastToStructChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/CastToStructChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -65,8 +65,7 @@
>                             "Casting a non-structure type to a structure type "
>                             "and accessing a field can lead to memory access "
>                             "errors or data corruption.");
> -      RangedBugReport *R = new RangedBugReport(*BT,BT->getDescription().c_str(),
> -                                               N);
> +      RangedBugReport *R = new RangedBugReport(*BT,BT->getDescription(), N);
>       R->addRange(CE->getSourceRange());
>       C.EmitReport(R);
>     }
> 
> Modified: cfe/trunk/lib/Analysis/DereferenceChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/DereferenceChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/DereferenceChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/DereferenceChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -62,7 +62,7 @@
>         BT_undef = new BuiltinBug("Dereference of undefined pointer value");
> 
>       EnhancedBugReport *report =
> -        new EnhancedBugReport(*BT_undef, BT_undef->getDescription().c_str(), N);
> +        new EnhancedBugReport(*BT_undef, BT_undef->getDescription(), N);
>       report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
>                                 bugreporter::GetDerefExpr(N));
>       C.EmitReport(report);
> @@ -93,7 +93,7 @@
>                                    "Dereference of null pointer");
> 
>         EnhancedBugReport *report =
> -          new EnhancedBugReport(*BT_null, BT_null->getDescription().c_str(), N);
> +          new EnhancedBugReport(*BT_null, BT_null->getDescription(), N);
>         report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
>                                   bugreporter::GetDerefExpr(N));
> 
> 
> Modified: cfe/trunk/lib/Analysis/DivZeroChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/DivZeroChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/DivZeroChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/DivZeroChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -68,7 +68,7 @@
>         BT = new BuiltinBug("Division by zero");
> 
>       EnhancedBugReport *R = 
> -        new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);
> +        new EnhancedBugReport(*BT, BT->getDescription(), N);
> 
>       R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
>                            bugreporter::GetDenomExpr(N));
> 
> Modified: cfe/trunk/lib/Analysis/FixedAddressChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/FixedAddressChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/FixedAddressChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/FixedAddressChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -59,8 +59,7 @@
>                           "Using a fixed address is not portable because that "
>                           "address will probably not be valid in all "
>                           "environments or platforms.");
> -    RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription().c_str(),
> -                                             N);
> +    RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription(), N);
>     R->addRange(B->getRHS()->getSourceRange());
>     C.EmitReport(R);
>   }
> 
> Modified: cfe/trunk/lib/Analysis/MallocChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MallocChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/MallocChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/MallocChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -123,7 +123,7 @@
>                          "Try to free a memory block that has been released");
>       // FIXME: should find where it's freed last time.
>       BugReport *R = new BugReport(*BT_DoubleFree, 
> -                                   BT_DoubleFree->getDescription().c_str(), N);
> +                                   BT_DoubleFree->getDescription(), N);
>       C.EmitReport(R);
>     }
>     return;
> @@ -152,7 +152,7 @@
>                      "Allocated memory never released. Potential memory leak.");
>         // FIXME: where it is allocated.
>         BugReport *R = new BugReport(*BT_Leak,
> -                                     BT_Leak->getDescription().c_str(), N);
> +                                     BT_Leak->getDescription(), N);
>         C.EmitReport(R);
>       }
>     }
> 
> Modified: cfe/trunk/lib/Analysis/PointerArithChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PointerArithChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/PointerArithChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/PointerArithChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -59,8 +59,7 @@
>                             "Pointer arithmetic done on non-array variables "
>                             "means reliance on memory layout, which is "
>                             "dangerous.");
> -      RangedBugReport *R = new RangedBugReport(*BT,BT->getDescription().c_str(),
> -                                               N);
> +      RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription(), N);
>       R->addRange(B->getSourceRange());
>       C.EmitReport(R);
>     }
> 
> Modified: cfe/trunk/lib/Analysis/PointerSubChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PointerSubChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/PointerSubChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/PointerSubChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -66,8 +66,7 @@
>       BT = new BuiltinBug("Pointer subtraction", 
>                           "Subtraction of two pointers that do not point to "
>                           "the same memory chunk may cause incorrect result.");
> -    RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription().c_str(),
> -                                             N);
> +    RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription(), N);
>     R->addRange(B->getSourceRange());
>     C.EmitReport(R);
>   }
> 
> Modified: cfe/trunk/lib/Analysis/ReturnPointerRangeChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReturnPointerRangeChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/ReturnPointerRangeChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/ReturnPointerRangeChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -88,7 +88,7 @@
> 
>     // Generate a report for this bug.
>     RangedBugReport *report = 
> -      new RangedBugReport(*BT, BT->getDescription().c_str(), N);
> +      new RangedBugReport(*BT, BT->getDescription(), N);
> 
>     report->addRange(RetE->getSourceRange());
> 
> 
> Modified: cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -88,7 +88,7 @@
>         << R->getString() << "' returned.";
>   }
> 
> -  RangedBugReport *report = new RangedBugReport(*BT, os.str().data(), N);
> +  RangedBugReport *report = new RangedBugReport(*BT, os.str(), N);
>   report->addRange(RS->getSourceRange());
>   if (range.isValid())
>     report->addRange(range);
> 
> Modified: cfe/trunk/lib/Analysis/ReturnUndefChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReturnUndefChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/ReturnUndefChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/ReturnUndefChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -60,7 +60,7 @@
>                         "Undefined or garbage value returned to caller");
> 
>   EnhancedBugReport *report = 
> -    new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);  
> +    new EnhancedBugReport(*BT, BT->getDescription(), N);
> 
>   report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, RetE);
> 
> 
> Modified: cfe/trunk/lib/Analysis/UndefinedArgChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UndefinedArgChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/UndefinedArgChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/UndefinedArgChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -46,8 +46,7 @@
>           BT = new BuiltinBug("Pass-by-value argument in function call is "
>                               "undefined");
>         // Generate a report for this bug.
> -        EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(),
> -                                                     N);
> +        EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
>         R->addRange((*I)->getSourceRange());
>         R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, *I);
>         C.EmitReport(R);
> 
> Modified: cfe/trunk/lib/Analysis/UndefinedArraySubscriptChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UndefinedArraySubscriptChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/UndefinedArraySubscriptChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/UndefinedArraySubscriptChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -46,8 +46,7 @@
>         BT = new BuiltinBug("Array subscript is undefined");
> 
>       // Generate a report for this bug.
> -      EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(),
> -                                                   N);
> +      EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
>       R->addRange(A->getIdx()->getSourceRange());
>       R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, 
>                            A->getIdx());
> 
> Modified: cfe/trunk/lib/Analysis/UndefinedAssignmentChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UndefinedAssignmentChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/UndefinedAssignmentChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/UndefinedAssignmentChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -39,7 +39,7 @@
>     BT = new BuiltinBug("Assigned value is garbage or undefined");
> 
>   // Generate a report for this bug.
> -  EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(), N);
> +  EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
> 
>   if (AssignE) {
>     const Expr *ex = 0;
> 
> Modified: cfe/trunk/lib/Analysis/VLASizeChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/VLASizeChecker.cpp?rev=88779&r1=88778&r2=88779&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Analysis/VLASizeChecker.cpp (original)
> +++ cfe/trunk/lib/Analysis/VLASizeChecker.cpp Sat Nov 14 06:08:24 2009
> @@ -64,7 +64,7 @@
>                                 "garbage value as its size");
> 
>     EnhancedBugReport *report =
> -      new EnhancedBugReport(*BT_undef, BT_undef->getName().c_str(), N);
> +      new EnhancedBugReport(*BT_undef, BT_undef->getName(), N);
>     report->addRange(SE->getSourceRange());
>     report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, SE);
>     C.EmitReport(report);
> @@ -84,7 +84,7 @@
>                                "size");
> 
>     EnhancedBugReport *report =
> -      new EnhancedBugReport(*BT_zero, BT_zero->getName().c_str(), N);
> +      new EnhancedBugReport(*BT_zero, BT_zero->getName(), N);
>     report->addRange(SE->getSourceRange());
>     report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, SE);
>     C.EmitReport(report);
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list