* p-valprint.c (pascal_object_print_value): Replace potentially
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Mon, 23 Jul 2012 18:08:29 +0000 (18:08 +0000)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Mon, 23 Jul 2012 18:08:29 +0000 (18:08 +0000)
unsafe alloca with xmalloc/xfree.
* valops.c (search_struct_method): Likewise.

gdb/ChangeLog
gdb/p-valprint.c
gdb/valops.c

index c4712518a1abee785c66d92c28632fc9ff4c47a8..062eefdd9320efaf189fa329e448cb0c243322a0 100644 (file)
@@ -1,3 +1,9 @@
+2012-07-23  Siddhesh Poyarekar  <siddhesh@redhat.com>
+
+       * p-valprint.c (pascal_object_print_value): Replace potentially
+       unsafe alloca with xmalloc/xfree.
+       * valops.c (search_struct_method): Likewise.
+
 2012-07-23  Tom Tromey  <tromey@redhat.com>
 
        * solib-svr4.c (enable_break): Update.
index b8434ed256fcb5685e4d74eb887714eaa2e0eee0..9f4461723d986de86694a9e3badfeba7f2dbbecd 100644 (file)
@@ -797,8 +797,11 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 
          if (boffset < 0 || boffset >= TYPE_LENGTH (type))
            {
-             /* FIXME (alloc): not safe is baseclass is really really big. */
-             gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
+             gdb_byte *buf;
+             struct cleanup *back_to;
+
+             buf = xmalloc (TYPE_LENGTH (baseclass));
+             back_to = make_cleanup (xfree, buf);
 
              base_valaddr = buf;
              if (target_read_memory (address + boffset, buf,
@@ -807,6 +810,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
              address = address + boffset;
              thisoffset = 0;
              boffset = 0;
+             do_cleanups (back_to);
            }
          else
            base_valaddr = valaddr;
index 97d889b2bcf14e5504e2d75d783faef9712f4714..f6d8441581d94455ae49dfdaad1318368a55468f 100644 (file)
@@ -2281,8 +2281,13 @@ search_struct_method (const char *name, struct value **arg1p,
 
          if (offset < 0 || offset >= TYPE_LENGTH (type))
            {
-             gdb_byte *tmp = alloca (TYPE_LENGTH (baseclass));
-             CORE_ADDR address = value_address (*arg1p);
+             gdb_byte *tmp;
+             struct cleanup *back_to;
+             CORE_ADDR address;
+
+             tmp = xmalloc (TYPE_LENGTH (baseclass));
+             back_to = make_cleanup (xfree, tmp);
+             address = value_address (*arg1p);
 
              if (target_read_memory (address + offset,
                                      tmp, TYPE_LENGTH (baseclass)) != 0)
@@ -2293,6 +2298,7 @@ search_struct_method (const char *name, struct value **arg1p,
                                                          address + offset);
              base_valaddr = value_contents_for_printing (base_val);
              this_offset = 0;
+             do_cleanups (back_to);
            }
          else
            {