Add note to check that all changes have been pushed before creating the source tarballs
[binutils-gdb.git] / binutils / rdcoff.c
index 4d18d47ca117ba9b299a1e935e254a46211ebb9a..79fcfb21814fbc6fdef786606846d9b65a57d77d 100644 (file)
@@ -84,7 +84,7 @@ static debug_type parse_coff_enum_type
 /* Return the slot for a type.  */
 
 static debug_type *
-coff_get_slot (struct coff_types **types, long indx)
+coff_get_slot (void *dhandle, struct coff_types **types, long indx)
 {
   unsigned int base_index;
 
@@ -96,7 +96,7 @@ coff_get_slot (struct coff_types **types, long indx)
 
   if (*types == NULL || (*types)->base_index != base_index)
     {
-      struct coff_types *n = xcalloc (1, sizeof (*n));
+      struct coff_types *n = debug_xzalloc (dhandle, sizeof (*n));
       n->next = *types;
       n->base_index = base_index;
       *types = n;
@@ -176,13 +176,13 @@ parse_coff_type (bfd *abfd, struct coff_symbols *symbols,
       return type;
     }
 
-  if (pauxent != NULL && pauxent->x_sym.x_tagndx.l > 0)
+  if (pauxent != NULL && (int32_t) pauxent->x_sym.x_tagndx.u32 > 0)
     {
       debug_type *slot;
 
       /* This is a reference to an existing type.  FIXME: gdb checks
         that the class is not C_STRTAG, nor C_UNTAG, nor C_ENTAG.  */
-      slot = coff_get_slot (types, pauxent->x_sym.x_tagndx.l);
+      slot = coff_get_slot (dhandle, types, pauxent->x_sym.x_tagndx.u32);
       if (*slot != DEBUG_TYPE_NULL)
        return *slot;
       else
@@ -309,7 +309,7 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols,
   if (name != NULL)
     ret = debug_name_type (dhandle, name, ret);
 
-  debug_type *slot = coff_get_slot (types, coff_symno);
+  debug_type *slot = coff_get_slot (dhandle, types, coff_symno);
   *slot = ret;
 
   return ret;
@@ -324,11 +324,11 @@ parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols,
 {
   long symend;
   int alloc;
-  debug_field *fields;
+  debug_field *fields, *xfields;
   int count;
   bool done;
 
-  symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
+  symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.u32;
 
   alloc = 10;
   fields = (debug_field *) xmalloc (alloc * sizeof *fields);
@@ -385,7 +385,8 @@ parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols,
 
        case C_FIELD:
          bitpos = bfd_asymbol_value (sym);
-         bitsize = auxent.x_sym.x_misc.x_lnsz.x_size;
+         if (psubaux != NULL)
+           bitsize = psubaux->x_sym.x_misc.x_lnsz.x_size;
          break;
 
        case C_EOS:
@@ -403,7 +404,10 @@ parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols,
          f = debug_make_field (dhandle, bfd_asymbol_name (sym), ftype,
                                bitpos, bitsize, DEBUG_VISIBILITY_PUBLIC);
          if (f == DEBUG_FIELD_NULL)
-           return DEBUG_TYPE_NULL;
+           {
+             free (fields);
+             return DEBUG_TYPE_NULL;
+           }
 
          if (count + 1 >= alloc)
            {
@@ -418,10 +422,13 @@ parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols,
     }
 
   fields[count] = DEBUG_FIELD_NULL;
+  xfields = debug_xalloc (dhandle, (count + 1) * sizeof (*fields));
+  memcpy (xfields, fields, (count + 1) * sizeof (*fields));
+  free (fields);
 
   return debug_make_struct_type (dhandle, ntype == T_STRUCT,
                                 pauxent->x_sym.x_misc.x_lnsz.x_size,
-                                fields);
+                                xfields);
 }
 
 /* Parse an enum type.  */
@@ -433,12 +440,12 @@ parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols,
 {
   long symend;
   int alloc;
-  const char **names;
-  bfd_signed_vma *vals;
+  const char **names, **xnames;
+  bfd_signed_vma *vals, *xvals;
   int count;
   bool done;
 
-  symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
+  symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.u32;
 
   alloc = 10;
   names = (const char **) xmalloc (alloc * sizeof *names);
@@ -491,8 +498,15 @@ parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols,
     }
 
   names[count] = NULL;
-
-  return debug_make_enum_type (dhandle, names, vals);
+  vals[count] = 0;
+  xnames = debug_xalloc (dhandle, (count + 1) * sizeof (*names));
+  memcpy (xnames, names, (count + 1) * sizeof (*names));
+  free (names);
+  xvals = debug_xalloc (dhandle, (count + 1) * sizeof (*vals));
+  memcpy (xvals, vals, (count + 1) * sizeof (*vals));
+  free (vals);
+
+  return debug_make_enum_type (dhandle, xnames, xvals);
 }
 
 /* Handle a single COFF symbol.  */
@@ -571,7 +585,7 @@ parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types **types,
 
        /* Store the named type into the slot, so that references get
            the name.  */
-       slot = coff_get_slot (types, coff_symno);
+       slot = coff_get_slot (dhandle, types, coff_symno);
        *slot = type;
       }
       break;