aboutsummaryrefslogtreecommitdiff
path: root/gas/read.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-01-27 10:31:56 +1030
committerAlan Modra <amodra@gmail.com>2023-01-27 15:38:52 +1030
commitc026360c7578b4599c289987981d9c9c80481e40 (patch)
tree695998bd2116183a34814b02cd44d44316f6674b /gas/read.c
parent48afe8b710712bf131fadbfa3278e512a7034483 (diff)
downloadgdb-c026360c7578b4599c289987981d9c9c80481e40.zip
gdb-c026360c7578b4599c289987981d9c9c80481e40.tar.gz
gdb-c026360c7578b4599c289987981d9c9c80481e40.tar.bz2
gas macro memory leaks
This tidies memory allocated for entries in macro_hash. Freeing the macro name requires a little restructuring of the define_macro interface due to the name being used in the error message, and exposed the fact that the name and other fields were not initialised by the iq2000 backend. There is also a fix for .macro .macro .endm .macro .macro .endm which prior to this patch reported mac.s:1: Warning: attempt to redefine pseudo-op `.macro' ignored mac.s:3: Error: Macro `.macro' was already defined rather than reporting the attempt to redefine twice. * macro.c (macro_del_f): New function. (macro_init): Use it when creating macro_hash. (free_macro): Free macro name too. (define_macro): Return the macro_entry, remove idx, file, line and namep params. Call as_where. Report errors here. Delete macro from macro_hash on attempt to redefined pseudo-op. (delete_macro): Don't call free_macro. * macro.h (define_macro): Update prototype. * read.c (s_macro): Adjust to suit. * config/tc-iq2000.c (iq2000_add_macro): Init all fields of macro_entry.
Diffstat (limited to 'gas/read.c')
-rw-r--r--gas/read.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/gas/read.c b/gas/read.c
index 8fb11e8..c5a477f 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -2647,13 +2647,8 @@ void
s_macro (int ignore ATTRIBUTE_UNUSED)
{
char *eol;
- const char * file;
- unsigned int line;
sb s;
- const char *err;
- const char *name;
-
- file = as_where (&line);
+ macro_entry *macro;
eol = find_end_of_line (input_line_pointer, 0);
sb_build (&s, eol - input_line_pointer);
@@ -2664,19 +2659,18 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
{
sb label;
size_t len;
+ const char *name;
name = S_GET_NAME (line_label);
len = strlen (name);
sb_build (&label, len);
sb_add_buffer (&label, name, len);
- err = define_macro (0, &s, &label, get_macro_line_sb, file, line, &name);
+ macro = define_macro (&s, &label, get_macro_line_sb);
sb_kill (&label);
}
else
- err = define_macro (0, &s, NULL, get_macro_line_sb, file, line, &name);
- if (err != NULL)
- as_bad_where (file, line, err, name);
- else
+ macro = define_macro (&s, NULL, get_macro_line_sb);
+ if (macro != NULL)
{
if (line_label != NULL)
{
@@ -2686,14 +2680,16 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
}
if (((NO_PSEUDO_DOT || flag_m68k_mri)
- && str_hash_find (po_hash, name) != NULL)
+ && str_hash_find (po_hash, macro->name) != NULL)
|| (!flag_m68k_mri
- && *name == '.'
- && str_hash_find (po_hash, name + 1) != NULL))
- as_warn_where (file,
- line,
- _("attempt to redefine pseudo-op `%s' ignored"),
- name);
+ && macro->name[0] == '.'
+ && str_hash_find (po_hash, macro->name + 1) != NULL))
+ {
+ as_warn_where (macro->file, macro->line,
+ _("attempt to redefine pseudo-op `%s' ignored"),
+ macro->name);
+ str_hash_delete (macro_hash, macro->name);
+ }
}
sb_kill (&s);