summaryrefslogtreecommitdiff
path: root/gas/input-scrub.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-06-09 13:21:59 +0000
committerH.J. Lu <hjl.tools@gmail.com>2012-06-09 13:21:59 +0000
commit89b5ea1131cdaec3aab07f5e8574c6148288f16d (patch)
treec0e774eb8e5c054072f7767b74df54d47a286de7 /gas/input-scrub.c
parentcb23c38305855e1502d1c0099ac9d9d0b7f6277b (diff)
downloadbinutils-redhat-89b5ea1131cdaec3aab07f5e8574c6148288f16d.tar.gz
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 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;