public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] gas: buffer_and_nest() needs to pass nul-terminated string to temp_ilp()
Date: Wed, 15 Feb 2023 07:46:15 +0000 (GMT)	[thread overview]
Message-ID: <20230215074615.DEBCE3858D35@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c22a74728313ee35f6bf143238d42e2eca9ed020

commit c22a74728313ee35f6bf143238d42e2eca9ed020
Author: Jan Beulich <jbeulich@suse.com>
Date:   Wed Feb 15 08:46:02 2023 +0100

    gas: buffer_and_nest() needs to pass nul-terminated string to temp_ilp()
    
    In 7545aa2dd2eb ("gas: improve interaction between read_a_source_file()
    and s_linefile()") I didn't pay attention to the dual purpose of the
    nul character previously used. This was to a fair degree because of the
    open-coding of certain operations. Insert the earlier found line
    terminator instead of a hard-coded newline, and do so early in this
    special case (bypassing the later general insertion point). Plus
    properly use sb_terminate() to mark the end of the string. (Note that
    saved_eol_char was misnamed: Without calling sb_terminate() there's
    simply random data at that position in the buffer.)

Diff:
---
 gas/macro.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gas/macro.c b/gas/macro.c
index f9f2d63e9f7..afcd48b3a88 100644
--- a/gas/macro.c
+++ b/gas/macro.c
@@ -263,13 +263,13 @@ buffer_and_nest (const char *from, const char *to, sb *ptr,
 	  if (from != NULL && strcasecmp (from, "MACRO") == 0
 	      && len >= 8 && strncasecmp (ptr->ptr + i, "linefile", 8) == 0)
 	    {
-	      char saved_eol_char = ptr->ptr[ptr->len];
-
-	      ptr->ptr[ptr->len] = '\n';
-	      temp_ilp (ptr->ptr + i + 8);
+	      sb_add_char (ptr, more);
+	      temp_ilp (sb_terminate (ptr) + i + 8);
 	      s_linefile (0);
 	      restore_ilp ();
-	      ptr->ptr[ptr->len] = saved_eol_char;
+	      line_start = ptr->len;
+	      more = get_line (ptr);
+	      continue;
 	    }
 	}

                 reply	other threads:[~2023-02-15  7:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230215074615.DEBCE3858D35@sourceware.org \
    --to=jbeulich@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).