r201628 - CIndex: initialise TU

Saleem Abdulrasool compnerd at compnerd.org
Tue Feb 18 18:56:56 PST 2014


Author: compnerd
Date: Tue Feb 18 20:56:55 2014
New Revision: 201628

URL: http://llvm.org/viewvc/llvm-project?rev=201628&view=rev
Log:
CIndex: initialise TU

TU is not guaranteed to be initialised in all cases.  In particular if CIdx or
ast_filename is NULL (or if &TU is NULL), then clang_createTranslationUnit2 will
not initialise the out parameter out_TU.  This is followed by an assertion check
which may perform a branch based on unitialised memory.

Caught by scan-build.

Modified:
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=201628&r1=201627&r2=201628&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Feb 18 20:56:55 2014
@@ -2612,7 +2612,7 @@ void clang_toggleCrashRecovery(unsigned
 
 CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
                                               const char *ast_filename) {
-  CXTranslationUnit TU;
+  CXTranslationUnit TU = NULL;
   enum CXErrorCode Result =
       clang_createTranslationUnit2(CIdx, ast_filename, &TU);
   (void)Result;





More information about the cfe-commits mailing list