]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/eval.c
gdb: fix regression in evaluate_funcall for non C++ like cases
[thirdparty/binutils-gdb.git] / gdb / eval.c
index 659493c8237ce4509e45bf031de624552edf4074..ab070a3d9f66c1fdcec059c659539b6f8df59607 100644 (file)
@@ -872,7 +872,9 @@ structop_base_operation::evaluate_funcall
      (struct type *expect_type, struct expression *exp, enum noside noside,
       const std::vector<operation_up> &args)
 {
-  std::vector<value *> vals (args.size () + 1);
+  /* Allocate space for the function call arguments.  Include space for a
+     `this' pointer at the start, and a trailing nullptr.  */
+  std::vector<value *> vals (args.size () + 2);
   /* First, evaluate the structure into vals[0].  */
   enum exp_opcode op = opcode ();
   if (op == STRUCTOP_STRUCT)
@@ -918,9 +920,16 @@ structop_base_operation::evaluate_funcall
        }
     }
 
+  /* Evaluate the arguments, and add the trailing nullptr.  The '+ 1' here
+     is to allow for the `this' pointer we placed into vals[0].  */
   for (int i = 0; i < args.size (); ++i)
     vals[i + 1] = args[i]->evaluate_with_coercion (exp, noside);
-  gdb::array_view<value *> arg_view = vals;
+  vals[args.size () + 1] = nullptr;
+
+  /* The array view includes the `this' pointer, but not the trailing
+     nullptr.  */
+  gdb::array_view<value *> arg_view
+    = gdb::make_array_view (&vals[0], args.size () + 1);
 
   int static_memfuncp;
   value *callee;
@@ -941,7 +950,7 @@ structop_base_operation::evaluate_funcall
     {
       struct value *temp = vals[0];
 
-      callee = value_struct_elt (&temp, &vals[1], tstr,
+      callee = value_struct_elt (&temp, &vals[0], tstr,
                                 &static_memfuncp,
                                 op == STRUCTOP_STRUCT
                                 ? "structure" : "structure pointer");