replace some raw xmalloc / xrealloc with the XNEW* macros
authorTrevor Saunders <tbsaunde@tbsaunde.org>
Sun, 14 Feb 2016 03:00:07 +0000 (22:00 -0500)
committerTrevor Saunders <tbsaunde+binutils@tbsaunde.org>
Tue, 22 Mar 2016 23:06:39 +0000 (19:06 -0400)
This increases consistancy of how we allocate memory, and always casting the
result to the proper type.  It also helps make sure we get any use of sizeof on
the result type correct.

gas/ChangeLog:

2016-03-22  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

* listing.c (listing_message): Use XNEW style allocation macros.
* read.c (read_a_source_file): Likewise.
(read_symbol_name): Likewise.
(s_mri_common): Likewise.
(assign_symbol): Likewise.
(s_reloc): Likewise.
(emit_expr_with_reloc): Likewise.
(s_incbin): Likewise.
(s_include): Likewise.
* sb.c (sb_build): Likewise.
(sb_check): Likewise.

gas/ChangeLog
gas/listing.c
gas/read.c
gas/sb.c

index 24cf393f946532c094ac66214c2c2dea167be8e9..4aa12925c403b949e78be63e48cdb35242d5e4bf 100644 (file)
@@ -1,3 +1,17 @@
+2016-03-22  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>
+
+       * listing.c (listing_message): Use XNEW style allocation macros.
+       * read.c (read_a_source_file): Likewise.
+       (read_symbol_name): Likewise.
+       (s_mri_common): Likewise.
+       (assign_symbol): Likewise.
+       (s_reloc): Likewise.
+       (emit_expr_with_reloc): Likewise.
+       (s_incbin): Likewise.
+       (s_include): Likewise.
+       * sb.c (sb_build): Likewise.
+       (sb_check): Likewise.
+
 2016-03-22  Alan Modra  <amodra@gmail.com>
 
        * write.c (record_alignment): Revert 2016-02-18 change.
index 4b5fd34cf8c41216f49de0f1121766342925b910..53e84aba311ce62033e920f58707b2532d0411ca 100644 (file)
@@ -236,7 +236,7 @@ listing_message (const char *name, const char *message)
     {
       unsigned int l = strlen (name) + strlen (message) + 1;
       char *n = (char *) xmalloc (l);
-      struct list_message *lm = xmalloc (sizeof *lm);
+      struct list_message *lm = XNEW (struct list_message);
       strcpy (n, name);
       strcat (n, message);
       lm->message = n;
index ea6d9f61df1aab3dd2925d4b2c236ccffcbadb52..a22c7505efebe4bb108e43118be9c7d1e616c541 100644 (file)
@@ -879,7 +879,7 @@ read_a_source_file (const char *name)
                      /* Copy it for safe keeping.  Also give an indication of
                         how much macro nesting is involved at this point.  */
                      len = s - input_line_pointer;
-                     copy = (char *) xmalloc (len + macro_nest + 2);
+                     copy = XNEWVEC (char, len + macro_nest + 2);
                      memset (copy, '>', macro_nest);
                      copy[macro_nest] = ' ';
                      memcpy (copy + macro_nest + 1, input_line_pointer, len);
@@ -1271,7 +1271,7 @@ read_a_source_file (const char *name)
                     that goes with this #APP  There is one.  The specs
                     guarantee it...  */
                  tmp_len = buffer_limit - s;
-                 tmp_buf = (char *) xmalloc (tmp_len + 1);
+                 tmp_buf = XNEWVEC (char, tmp_len + 1);
                  memcpy (tmp_buf, s, tmp_len);
                  do
                    {
@@ -1287,7 +1287,7 @@ read_a_source_file (const char *name)
                      else
                        num = buffer_limit - buffer;
 
-                     tmp_buf = (char *) xrealloc (tmp_buf, tmp_len + num);
+                     tmp_buf = XRESIZEVEC (char, tmp_buf, tmp_len + num);
                      memcpy (tmp_buf + tmp_len, buffer, num);
                      tmp_len += num;
                    }
@@ -1308,7 +1308,7 @@ read_a_source_file (const char *name)
              scrub_string_end = ends;
 
              new_length = ends - s;
-             new_buf = (char *) xmalloc (new_length);
+             new_buf = XNEWVEC (char, new_length);
              new_tmp = new_buf;
              for (;;)
                {
@@ -1324,7 +1324,7 @@ read_a_source_file (const char *name)
                      break;
                    }
 
-                 new_buf = (char *) xrealloc (new_buf, new_length + 100);
+                 new_buf = XRESIZEVEC (char, new_buf, new_length + 100);
                  new_tmp = new_buf + new_length;
                  new_length += 100;
                }
@@ -1657,7 +1657,7 @@ read_symbol_name (void)
       char * name_end;
       unsigned int C;
 
-      start = name = xmalloc (len + 1);
+      start = name = XNEWVEC (char, len + 1);
 
       name_end = name + SYM_NAME_CHUNK_LEN;
 
@@ -1669,7 +1669,7 @@ read_symbol_name (void)
 
              sofar = name - start;
              len += SYM_NAME_CHUNK_LEN;
-             start = xrealloc (start, len + 1);
+             start = XRESIZEVEC (char, start, len + 1);
              name_end = start + len;
              name = start + sofar;
            }
@@ -1697,7 +1697,7 @@ read_symbol_name (void)
        ;
 
       len = (input_line_pointer - name) - 1;
-      start = xmalloc (len + 1);
+      start = XNEWVEC (char, len + 1);
 
       memcpy (start, name, len);
       start[len] = 0;
@@ -1850,9 +1850,8 @@ s_mri_common (int small ATTRIBUTE_UNUSED)
 
       if (line_label != NULL)
        {
-         alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
-                                 + (input_line_pointer - name)
-                                 + 1);
+         alc = XNEWVEC (char, strlen (S_GET_NAME (line_label))
+                        + (input_line_pointer - name) + 1);
          sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
          name = alc;
        }
@@ -3238,7 +3237,7 @@ assign_symbol (char *name, int mode)
       if (listing & LISTING_SYMBOLS)
        {
          extern struct list_info_struct *listing_tail;
-         fragS *dummy_frag = (fragS *) xcalloc (1, sizeof (fragS));
+         fragS *dummy_frag = XCNEW (fragS);
          dummy_frag->line = listing_tail;
          dummy_frag->fr_symbol = symbolP;
          symbol_set_frag (symbolP, dummy_frag);
@@ -4067,7 +4066,7 @@ s_reloc (int ignore ATTRIBUTE_UNUSED)
     { "64", BFD_RELOC_64 }
   };
 
-  reloc = (struct reloc_list *) xmalloc (sizeof (*reloc));
+  reloc = XNEW (struct reloc_list);
 
   if (flag_mri)
     stop = mri_comment_field (&stopc);
@@ -4347,7 +4346,7 @@ emit_expr_with_reloc (expressionS *exp,
     {
       struct broken_word *x;
 
-      x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
+      x = XNEW (struct broken_word);
       x->next_broken_word = broken_words;
       broken_words = x;
       x->seg = now_seg;
@@ -5858,7 +5857,7 @@ s_incbin (int x ATTRIBUTE_UNUSED)
     {
       int i;
 
-      path = (char *) xmalloc ((unsigned long) len + include_dir_maxlen + 5);
+      path = XNEWVEC (char, (unsigned long) len + include_dir_maxlen + 5);
 
       for (i = 0; i < include_dir_count; i++)
        {
@@ -5961,8 +5960,8 @@ s_include (int arg ATTRIBUTE_UNUSED)
     }
 
   demand_empty_rest_of_line ();
-  path = (char *) xmalloc ((unsigned long) i
-                          + include_dir_maxlen + 5 /* slop */ );
+  path = XNEWVEC (char, (unsigned long) i
+                 + include_dir_maxlen + 5 /* slop */ );
 
   for (i = 0; i < include_dir_count; i++)
     {
index ed471b86c07e70573dce43bc56442364585b14e7..76d555e34024d2fe40ba2db28535479ff135fa4a 100644 (file)
--- a/gas/sb.c
+++ b/gas/sb.c
@@ -59,7 +59,7 @@ static void sb_check (sb *, size_t);
 void
 sb_build (sb *ptr, size_t size)
 {
-  ptr->ptr = xmalloc (size + 1);
+  ptr->ptr = XNEWVEC (char, size + 1);
   ptr->max = size;
   ptr->len = 0;
 }
@@ -147,7 +147,7 @@ sb_check (sb *ptr, size_t len)
 #endif
       max -= MALLOC_OVERHEAD + 1;
       ptr->max = max;
-      ptr->ptr = xrealloc (ptr->ptr, max + 1);
+      ptr->ptr = XRESIZEVEC (char, ptr->ptr, max + 1);
     }
 }
 
This page took 0.032187 seconds and 4 git commands to generate.