aboutsummaryrefslogtreecommitdiff
path: root/gas/input-scrub.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-06-09 13:22:00 +0000
committerH.J. Lu <hjl.tools@gmail.com>2012-06-09 13:22:00 +0000
commitd2ae702c466d7d01de50427a048df0cfd5b90e24 (patch)
treeb9db44b3aa2e47d6ae8bb075d4b3b691e1fee4b1 /gas/input-scrub.c
parent5197bfb548f1f12137e65c843ae1a3c1899ea17e (diff)
downloadgdb-d2ae702c466d7d01de50427a048df0cfd5b90e24.zip
gdb-d2ae702c466d7d01de50427a048df0cfd5b90e24.tar.gz
gdb-d2ae702c466d7d01de50427a048df0cfd5b90e24.tar.bz2
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.
Diffstat (limited to 'gas/input-scrub.c')
-rw-r--r--gas/input-scrub.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/gas/input-scrub.c b/gas/input-scrub.c
index 46dd244..adae4d4 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;