diff options
author | Trevor Saunders <tbsaunde@tbsaunde.org> | 2016-02-13 22:00:07 -0500 |
---|---|---|
committer | Trevor Saunders <tbsaunde+binutils@tbsaunde.org> | 2016-03-22 19:06:39 -0400 |
commit | 8860a416a2357aa66a03218c6076b95ef8052ccf (patch) | |
tree | 496266d5cf13fa6ddd41b8236141e2aca1eef7f1 | |
parent | 34b9f7292f9c75d09c169a293c1f021eb97517ca (diff) | |
download | gdb-8860a416a2357aa66a03218c6076b95ef8052ccf.zip gdb-8860a416a2357aa66a03218c6076b95ef8052ccf.tar.gz gdb-8860a416a2357aa66a03218c6076b95ef8052ccf.tar.bz2 |
replace some raw xmalloc / xrealloc with the XNEW* macros
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.
-rw-r--r-- | gas/ChangeLog | 14 | ||||
-rw-r--r-- | gas/listing.c | 2 | ||||
-rw-r--r-- | gas/read.c | 33 | ||||
-rw-r--r-- | gas/sb.c | 4 |
4 files changed, 33 insertions, 20 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index 24cf393..4aa1292 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -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. diff --git a/gas/listing.c b/gas/listing.c index 4b5fd34..53e84ab 100644 --- a/gas/listing.c +++ b/gas/listing.c @@ -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; @@ -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++) { @@ -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); } } |