This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Ping: [RFA:] .error "msg" and .warning "msg" directives.
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: binutils at sources dot redhat dot com
- Date: Mon, 22 Nov 2004 14:06:14 +0100
- Subject: Re: Ping: [RFA:] .error "msg" and .warning "msg" directives.
> 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