]> granicus.if.org Git - clang/commitdiff
CIndex: initialise TU
authorSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 19 Feb 2014 02:56:55 +0000 (02:56 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 19 Feb 2014 02:56:55 +0000 (02:56 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201628 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/CIndex.cpp

index e862889f26367c2f565704660e9fc7f517f4540e..c5f41a8a7422e1447484bf81f1a18aaf2a486509 100644 (file)
@@ -2612,7 +2612,7 @@ void clang_toggleCrashRecovery(unsigned isEnabled) {
 
 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;