From 89b5ea1131cdaec3aab07f5e8574c6148288f16d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 9 Jun 2012 13:21:59 +0000 Subject: Allocate sufficient space for string buffer * input-scrub.c (input_scrub_include_sb): Use sb_build to allocate sufficient space for from_sb. Use sb_terminate to terminate string. * read.c (read_a_source_file): Use sb_build to allocate sufficient space and replace sb_add_string with sb_add_buffer. (s_macro): Likewise. (input_scrub_insert_line): Likewise. (s_irp): Use sb_build to allocate sufficient space. (do_repeat): Use sb_build to allocate sufficient space for many. * sb.c (sb_build): Remove static. * sb.h (sb_build): New prototype. --- gas/input-scrub.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'gas/input-scrub.c') diff --git a/gas/input-scrub.c b/gas/input-scrub.c index 46dd244a98..adae4d4dcd 100644 --- a/gas/input-scrub.c +++ b/gas/input-scrub.c @@ -264,6 +264,8 @@ input_scrub_include_file (char *filename, char *position) void input_scrub_include_sb (sb *from, char *position, int is_expansion) { + int newline; + if (macro_nest > max_macro_nest) as_fatal (_("macros nested too deeply")); ++macro_nest; @@ -277,9 +279,11 @@ input_scrub_include_sb (sb *from, char *position, int is_expansion) next_saved_file = input_scrub_push (position); - sb_new (&from_sb); + /* Allocate sufficient space: from->len + optional newline. */ + newline = from->len >= 1 && from->ptr[0] != '\n'; + sb_build (&from_sb, from->len + newline); from_sb_is_expansion = is_expansion; - if (from->len >= 1 && from->ptr[0] != '\n') + if (newline) { /* Add the sentinel required by read.c. */ sb_add_char (&from_sb, '\n'); @@ -288,8 +292,7 @@ input_scrub_include_sb (sb *from, char *position, int is_expansion) /* Make sure the parser looks at defined contents when it scans for e.g. end-of-line at the end of a macro. */ - sb_add_char (&from_sb, 0); - from_sb.len--; + sb_terminate (&from_sb); sb_index = 1; -- cgit v1.2.1