* cp-valprint.c (cp_print_value): Replace potentially unsafe
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Fri, 6 Jul 2012 05:36:07 +0000 (05:36 +0000)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Fri, 6 Jul 2012 05:36:07 +0000 (05:36 +0000)
        alloca with xmalloc/xfree.

gdb/ChangeLog
gdb/cp-valprint.c

index 355c2755e7b84f9d3feecd57538444cee70731b2..e432894d5d150924448b8b1404dafb80ccac2c63 100644 (file)
@@ -1,3 +1,9 @@
+2012-07-06  Siddhesh Poyarekar  <siddhesh@redhat.com>
+           Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       * cp-valprint.c (cp_print_value): Replace potentially unsafe
+       alloca with xmalloc/xfree.
+
 2012-07-06  Siddhesh Poyarekar  <siddhesh@redhat.com>
 
        * MAINTAINERS (Write After Approval): Add myself to the list.
index 2e3beeaf324cc939896a0be69b6099d90c1e559c..c066aa5e742d7166c01012e0d46d1b885ba30ee4 100644 (file)
@@ -554,9 +554,11 @@ cp_print_value (struct type *type, struct type *real_type,
              if ((boffset + offset) < 0
                  || (boffset + offset) >= TYPE_LENGTH (real_type))
                {
-                 /* FIXME (alloca): unsafe if baseclass is really
-                    really large.  */
-                 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);
 
                  if (target_read_memory (address + boffset, buf,
                                          TYPE_LENGTH (baseclass)) != 0)
@@ -568,6 +570,7 @@ cp_print_value (struct type *type, struct type *real_type,
                  boffset = 0;
                  thistype = baseclass;
                  base_valaddr = value_contents_for_printing_const (base_val);
+                 do_cleanups (back_to);
                }
              else
                {