public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Hans-Peter Nilsson <hans-peter.nilsson@axis.com>
To: binutils@sources.redhat.com
Subject: Re: Ping: [RFA:] .error "msg" and .warning "msg" directives.
Date: Mon, 22 Nov 2004 13:06:00 -0000	[thread overview]
Message-ID: <200411221306.iAMD6Emt014237@ignucius.se.axis.com> (raw)
In-Reply-To: <20041115034849.GJ32175@bubble.modra.org> (message from Alan Modra on Mon, 15 Nov 2004 14:18:49 +1030)

> Date: Mon, 15 Nov 2004 14:18:49 +1030
> From: Alan Modra <amodra@bigpond.net.au>

> On Fri, Nov 12, 2004 at 11:43:37AM +0100, Hans-Peter Nilsson wrote:
> > Ping: <URL:http://sourceware.org/ml/binutils/2004-11/msg00064.html>.
> 
> > +   char *msg = err
> > +     ? _(".error directive invoked in source file")
> > +     : _(".warning directive invoked in source file");
> 
> No need to internationalize the directive (and parens needed before
> err for proper formatting).
> 
>   char *msg = _("%s directive invoked in source file");
> .
> .
>   if (err)
>     as_bad (msg, ".error");
>   else
>     as_warn (msg, ".warning");
> 
> OK with that change.

I had a brief conversation with Alan regarding:
- msg is normally set from the demand_copy_C_string call, so it
needs to be self-contained, assuming we want to avoid adding
arguments to as_bad and as_warn that aren't matched by the
format string.
- that implies that I missed adding a comment to point that out.
- I also missed that I should use "%s" as the format string,
else I introduce a security hole or at least a means to crash
gas by bad input.

This is the updated read.c part, the rest checked in as-was
(as-new pun elided).

Index: read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.80
diff -p -c -r1.80 read.c
*** read.c	10 Nov 2004 03:28:44 -0000	1.80
--- read.c	22 Nov 2004 12:52:53 -0000
*************** static const pseudo_typeS potable[] = {
*** 306,311 ****
--- 306,312 ----
    {"equ", s_set, 0},
    {"equiv", s_set, 1},
    {"err", s_err, 0},
+   {"error", s_errwarn, 1},
    {"exitm", s_mexit, 0},
  /* extend  */
    {"extern", s_ignore, 0},	/* We treat all undef as ext.  */
*************** static const pseudo_typeS potable[] = {
*** 411,416 ****
--- 412,418 ----
    {"xdef", s_globl, 0},
    {"xref", s_ignore, 0},
    {"xstabs", s_xstab, 's'},
+   {"warning", s_errwarn, 0},
    {"word", cons, 2},
    {"zero", s_space, 0},
    {NULL, NULL, 0}			/* End sentinel.  */
*************** s_err (int ignore ATTRIBUTE_UNUSED)
*** 1665,1670 ****
--- 1667,1709 ----
    demand_empty_rest_of_line ();
  }
  
+ /* Handle the .error and .warning pseudo-ops.  */
+ 
+ void
+ s_errwarn (int err)
+ {
+   int len;
+   /* The purpose for the conditional assignment is not to
+      internationalize the directive itself, but that we need a
+      self-contained message, one that can be passed like the
+      demand_copy_C_string return value, and with no assumption on the
+      location of the name of the directive within the message.  */
+   char *msg
+     = (err ? _(".error directive invoked in source file")
+        : _(".warning directive invoked in source file"));
+ 
+   if (!is_it_end_of_statement ())
+     {
+       if (*input_line_pointer != '\"')
+ 	{
+ 	  as_bad (_("%s argument must be a string"),
+ 		  err ? ".error" : ".warning");
+ 	  discard_rest_of_line ();
+ 	  return;
+ 	}
+ 
+       msg = demand_copy_C_string (&len);
+       if (msg == NULL)
+ 	return;
+     }
+ 
+   if (err)
+     as_bad ("%s", msg);
+   else
+     as_warn ("%s", msg);
+   demand_empty_rest_of_line ();
+ }
+ 
  /* Handle the MRI fail pseudo-op.  */
  
  void

brgds, H-P

      reply	other threads:[~2004-11-22 13:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-12 10:43 Hans-Peter Nilsson
2004-11-15  3:48 ` Alan Modra
2004-11-22 13:06   ` Hans-Peter Nilsson [this message]

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=200411221306.iAMD6Emt014237@ignucius.se.axis.com \
    --to=hans-peter.nilsson@axis.com \
    --cc=binutils@sources.redhat.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).