public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 1/3] x86: parse_real_register() does not alter the parsed string
Date: Fri, 31 Mar 2023 12:04:54 +0200	[thread overview]
Message-ID: <bcc26bf7-bb9f-6ffc-51e8-05b8ff9e05e1@suse.com> (raw)
In-Reply-To: <ae00493d-55a2-da0f-1d97-620424c7136b@suse.com>

Follow the model of strtol() et al - input string is const-qualified to
signal that the string isn't altered, but the returned "end" pointer is
not const-qualified, requiring const to be cast away (which generally is
a bad idea, but the alternative would be more convoluted code).

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -13749,9 +13749,9 @@ static bool check_register (const reg_en
 /* REG_STRING starts *before* REGISTER_PREFIX.  */
 
 static const reg_entry *
-parse_real_register (char *reg_string, char **end_op)
+parse_real_register (const char *reg_string, char **end_op)
 {
-  char *s = reg_string;
+  const char *s = reg_string;
   char *p;
   char reg_name_given[MAX_REG_NAME_SIZE + 1];
   const reg_entry *r;
@@ -13774,7 +13774,7 @@ parse_real_register (char *reg_string, c
   if (is_part_of_name (*s))
     return (const reg_entry *) NULL;
 
-  *end_op = s;
+  *end_op = (char *) s;
 
   r = (const reg_entry *) str_hash_find (reg_hash, reg_name_given);
 
@@ -13802,7 +13802,7 @@ parse_real_register (char *reg_string, c
 		++s;
 	      if (*s == ')')
 		{
-		  *end_op = s + 1;
+		  *end_op = (char *) s + 1;
 		  know (r[fpr].reg_num == fpr);
 		  return r + fpr;
 		}


  reply	other threads:[~2023-03-31 10:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31 10:03 [PATCH 0/3] better fix for PR gas/30248 Jan Beulich
2023-03-31 10:04 ` Jan Beulich [this message]
2023-03-31 10:05 ` [PATCH 2/3] x86: parse_register() must not alter the parsed string Jan Beulich
2023-03-31 10:07 ` [PATCH 3/3] gas: document that get_symbol_name() can clobber the input buffer Jan Beulich

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=bcc26bf7-bb9f-6ffc-51e8-05b8ff9e05e1@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /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).