This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA/Ada] guard against a malloc failure


First fix for the test failure mentioned in:
http://sourceware.org/ml/gdb-patches/2008-11/msg00718.html

ada_template_to_fixed_record_type_1 builds a fixed-size record type
from the run-time values of its discriminants. If the record contains
dynamic field, and if its discriminants are not initialized, the type
may end up to be unreasonably big and GDB may fail to allocate a value
of this type. This patch adds a check for such a case.

OK to apply?

2008-11-27  Jerome Guitton  <guitton@adacore.com>

	* ada-lang.c (ada_template_to_fixed_record_type_1): Check size
        of type to guard against a crash.

--- ada-lang.c.prev	2008-11-27 15:03:45.000000000 +0100
+++ ada-lang.c	2008-11-27 15:24:48.000000000 +0100
@@ -6883,7 +6883,15 @@ ada_template_to_fixed_record_type_1 (str
       else if (is_dynamic_field (type, f))
         {
           if (dval0 == NULL)
-            dval = value_from_contents_and_address (rtype, valaddr, address);
+	    {
+              /* rtype's length is computed based on the run-time
+                 value of discriminants. If the discriminants are not
+                 initialized, the type size may be completely bogus and
+                 GDB may fail to allocate a value for it. So check the
+                 size first before creating the value.  */
+	      check_size (rtype);
+	      dval = value_from_contents_and_address (rtype, valaddr, address);
+	    }
           else
             dval = dval0;
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]