[Lldb-commits] [PATCH] D41427: [lldb] Fix crash when parsing the type of a function without any arguments

Aaron Smith via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 19 20:43:58 PST 2017


asmith created this revision.
asmith added reviewers: zturner, lldb-commits.

For `int main()`, the number of arguments is zero. Trying to access the element of a null array causes trouble.


Repository:
  rL LLVM

https://reviews.llvm.org/D41427

Files:
  source/Plugins/SymbolFile/PDB/PDBASTParser.cpp


Index: source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===================================================================
--- source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -141,7 +141,7 @@
   } else if (auto func_sig = llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) {
     auto arg_enum = func_sig->getArguments();
     uint32_t num_args = arg_enum->getChildCount();
-    std::vector<CompilerType> arg_list(num_args);
+    std::vector<CompilerType> arg_list;
     while (auto arg = arg_enum->getNext()) {
       lldb_private::Type *arg_type =
           m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId());
@@ -152,6 +152,8 @@
       CompilerType arg_ast_type = arg_type->GetFullCompilerType();
       arg_list.push_back(arg_ast_type);
     }
+    lldbassert(arg_list.size() <= num_args);
+
     auto pdb_return_type = func_sig->getReturnType();
     lldb_private::Type *return_type =
         m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId());
@@ -166,7 +168,7 @@
     if (func_sig->isVolatileType())
       type_quals |= clang::Qualifiers::Volatile;
     CompilerType func_sig_ast_type = m_ast.CreateFunctionType(
-        return_ast_type, &arg_list[0], num_args, false, type_quals);
+        return_ast_type, arg_list.data(), arg_list.size(), false, type_quals);
 
     return std::make_shared<lldb_private::Type>(
         func_sig->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), 0,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41427.127656.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20171220/d4c6722e/attachment.bin>


More information about the lldb-commits mailing list