diff options
author | Nick Clifton <nickc@redhat.com> | 2017-01-12 14:56:13 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2017-01-12 14:56:13 +0000 |
commit | 1181551ef0a9a7f611a3d1130d2b284280882870 (patch) | |
tree | b40313309126c08dd0958ee0506f41910c2ef9ce /gas/read.c | |
parent | d95014a2ef6e9aee927c13960fa37e509d46eb32 (diff) | |
download | gdb-1181551ef0a9a7f611a3d1130d2b284280882870.zip gdb-1181551ef0a9a7f611a3d1130d2b284280882870.tar.gz gdb-1181551ef0a9a7f611a3d1130d2b284280882870.tar.bz2 |
Prevent internal assembler errors if a stabs creation function builds an badly formatted input string.
* read.c (temp_ilp): New function. Installs a temporary input
line pointer.
(restore_ilp): New function. Restores the original input line
pointer.
* read.h (temp_ilp): Prototype.
(restore_ilp): Prototype.
* stabs.c (dot_func_p): Use bfd_boolean type.
(generate_asm_file): Use temp_ilp and restore_ilp.
(stabs_generate_asm_lineno): Likewise.
(stabs_generate_asm_endfunc): Likewise.
Diffstat (limited to 'gas/read.c')
-rw-r--r-- | gas/read.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -6333,3 +6333,47 @@ find_end_of_line (char *s, int mri_string) { return _find_end_of_line (s, mri_string, 0, 0); } + +static char *saved_ilp = NULL; +static char *saved_limit; + +/* Use BUF as a temporary input pointer for calling other functions in this + file. BUF must be a C string, so that its end can be found by strlen. + Also sets the buffer_limit variable (local to this file) so that buffer + overruns should not occur. Saves the current input line pointer so that + it can be restored by calling restore_ilp(). + + Does not support recursion. + + FIXME: This function is currently only used by stabs.c but that + should be extended to other files in the gas source directory. */ + +void +temp_ilp (char *buf) +{ + gas_assert (saved_ilp == NULL); + gas_assert (buf != NULL); + + saved_ilp = input_line_pointer; + saved_limit = buffer_limit; + /* Prevent the assert in restore_ilp from triggering if + the input_line_pointer has not yet been initialised. */ + if (saved_ilp == NULL) + saved_limit = saved_ilp = (char *) ""; + + input_line_pointer = buf; + buffer_limit = buf + strlen (buf); +} + +/* Restore a saved input line pointer. */ + +void +restore_ilp (void) +{ + gas_assert (saved_ilp != NULL); + + input_line_pointer = saved_ilp; + buffer_limit = saved_limit; + + saved_ilp = NULL; +} |