public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] modula2: Don't treat % in Modula 2 messages specially
@ 2022-12-19 11:19 Jakub Jelinek
  2022-12-19 13:21 ` Gaius Mulley
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-12-19 11:19 UTC (permalink / raw)
  To: Gaius Mulley; +Cc: gcc-patches

Hi!

On top of the just posted patch, this patch makes sure that
any % chars in message strings aren't treated as format chars.
None of these functions take variable number of arguments, so for
most of format specifiers there is nowhere to take arguments from,
it is true that a couple of format specifiers don't take any
arguments - %%, %m, %<, %>, %' - so it is actually possible
to use them, but one needs to verify that no other are emitted and
that what should be printed as % is really emitted as %%.
If the FE does that, then please ignore this patch, otherwise I think
it is safer to do this.

Bootstrapped/regtested on x86_64-linux and i686-linux.

2022-12-19  Jakub Jelinek  <jakub@redhat.com>

	* gm2-gcc/m2linemap.cc (m2linemap_ErrorAt, m2linemap_ErrorAtf,
	m2linemap_WarningAtf, m2linemap_NoteAtf, m2linemap_internal_error):
	Call functions with "%s", message rather than just message, so that
	% chars in message aren't treated as format specifiers.

--- gcc/m2/gm2-gcc/m2linemap.cc.jj	2022-12-18 22:23:08.825497256 +0100
+++ gcc/m2/gm2-gcc/m2linemap.cc	2022-12-18 22:24:13.104563212 +0100
@@ -177,7 +177,7 @@ EXTERN
 void
 m2linemap_ErrorAt (location_t location, char *message)
 {
-  error_at (location, message);
+  error_at (location, "%s", message);
 }
 
 /* m2linemap_ErrorAtf - wraps up an error message.  */
@@ -198,7 +198,7 @@ m2linemap_ErrorAtf_1 (location_t locatio
 void
 m2linemap_ErrorAtf (location_t location, const char *message)
 {
-  m2linemap_ErrorAtf_1 (location, message);
+  m2linemap_ErrorAtf_1 (location, "%s", message);
 }
 
 /* m2linemap_WarningAtf - wraps up a warning message.  */
@@ -219,7 +219,7 @@ m2linemap_WarningAtf_1 (location_t locat
 void
 m2linemap_WarningAtf (location_t location, const char *message)
 {
-  m2linemap_WarningAtf_1 (location, message);
+  m2linemap_WarningAtf_1 (location, "%s", message);
 }
 
 /* m2linemap_NoteAtf - wraps up a note message.  */
@@ -240,7 +240,7 @@ m2linemap_NoteAtf_1 (location_t location
 void
 m2linemap_NoteAtf (location_t location, const char *message)
 {
-  m2linemap_NoteAtf_1 (location, message);
+  m2linemap_NoteAtf_1 (location, "%s", message);
 }
 
 /* m2linemap_internal_error - allow Modula-2 to use the GCC internal error.  */
@@ -248,7 +248,7 @@ m2linemap_NoteAtf (location_t location,
 void
 m2linemap_internal_error (const char *message)
 {
-  internal_error (message);
+  internal_error ("%s", message);
 }
 
 /* UnknownLocation - return the predefined location representing an

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] modula2: Don't treat % in Modula 2 messages specially
  2022-12-19 11:19 [PATCH] modula2: Don't treat % in Modula 2 messages specially Jakub Jelinek
@ 2022-12-19 13:21 ` Gaius Mulley
  0 siblings, 0 replies; 2+ messages in thread
From: Gaius Mulley @ 2022-12-19 13:21 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

Jakub Jelinek <jakub@redhat.com> writes:

> Hi!
>
> On top of the just posted patch, this patch makes sure that
> any % chars in message strings aren't treated as format chars.
> None of these functions take variable number of arguments, so for
> most of format specifiers there is nowhere to take arguments from,
> it is true that a couple of format specifiers don't take any
> arguments - %%, %m, %<, %>, %' - so it is actually possible
> to use them, but one needs to verify that no other are emitted and
> that what should be printed as % is really emitted as %%.
> If the FE does that, then please ignore this patch, otherwise I think
> it is safer to do this.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux.

yes it might be possible for % to slip though.  Thus much safer to avoid
the situation by using the patch.

LGTM

regards,
Gaius

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-19 13:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 11:19 [PATCH] modula2: Don't treat % in Modula 2 messages specially Jakub Jelinek
2022-12-19 13:21 ` Gaius Mulley

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).