public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RFA: Sanitize deprecation messages (PR 84195)
@ 2018-02-05 17:07 Nick Clifton
  2018-02-05 19:00 ` Martin Sebor
  0 siblings, 1 reply; 25+ messages in thread
From: Nick Clifton @ 2018-02-05 17:07 UTC (permalink / raw)
  To: msebor, dodji, dmalcolm; +Cc: gcc-patches

Hi Martin, Hi Dodji, Hi David,

  PR 84195 makes the point that deprecation messages do not follow the
  formatting guidelines set out by the -fmessage-length option, and that
  they could even contain unwanted control characters:
  
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84195

  Below is my attempt at a patch to fix this.  It is not very clever,
  just replacing the control characters with spaces, and doing it each
  time that a deprecation warning is displayed.  But I figured that
  such warnings are going to be rare and do not need to be efficiently
  handled.  So I choose to keep it simple. :-)

  No regressions with an x86_64-pc-linux-gnu toolchain.

  OK to apply ?

Cheers
  Nick

gcc/ChangeLog
2018-02-05  Nick Clifton  <nickc@redhat.com>

	PR 84195
	* tree.c (warn_deprecated_use): Sanitize deprecation messages.

Index: gcc/tree.c
===================================================================
--- gcc/tree.c	(revision 257389)
+++ gcc/tree.c	(working copy)
@@ -12436,6 +12436,39 @@
   else
     msg = NULL;
 
+  char * new_msg = NULL;
+  if (msg)
+    {
+      unsigned int i; /* FIXME: Do we need to check to see if msg is longer
+			 than 2^32 ?  */
+
+      /* PR 84195: Sanitize the message:
+	 
+	 If -fmessage-length is set to 0 then replace newline characters with
+	 spaces.  Replace other non-printing ASCII characters with spaces too.
+
+	 We do this check here, rather than where the deprecated attribute is
+	 recorded because the setting of -fmessage-length can be changed
+	 between those two locations.  */
+      for (i = 0; i < strlen (msg); i++)
+	{
+	  char c = msg[i];
+	  
+	  if (! ISCNTRL (c))
+	    continue;
+
+	  if (c != '\n' || ! pp_is_wrapping_line (global_dc->printer))
+	    {
+	      if (new_msg == NULL)
+		new_msg = xstrdup (msg);
+	      new_msg [i] = ' ';
+	    }
+	}
+
+      if (new_msg)
+	msg = new_msg;
+    }
+
   bool w;
   if (DECL_P (node))
     {
@@ -12505,6 +12538,8 @@
 	    }
 	}
     }
+
+  free (new_msg);
 }
 
 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration

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

end of thread, other threads:[~2018-06-18 17:56 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-05 17:07 RFA: Sanitize deprecation messages (PR 84195) Nick Clifton
2018-02-05 19:00 ` Martin Sebor
2018-02-06 12:39   ` Nick Clifton
2018-02-06 14:00     ` David Malcolm
2018-02-06 17:13     ` Martin Sebor
2018-02-07 17:27       ` Nick Clifton
2018-02-07 19:17         ` David Malcolm
2018-02-08 11:04           ` Nick Clifton
2018-02-08 16:31             ` Martin Sebor
2018-02-09 13:01               ` Nick Clifton
2018-02-15 21:04                 ` David Malcolm
2018-02-16 12:14                   ` Trevor Saunders
2018-02-16 15:38                     ` David Malcolm
2018-02-16 12:43                   ` Nick Clifton
2018-02-16 15:33                     ` David Malcolm
2018-02-16 16:19                     ` Martin Sebor
2018-02-20 12:48                       ` Nick Clifton
2018-02-21  0:07                         ` Martin Sebor
2018-06-18 17:56                       ` Jason Merrill
2018-05-02 17:00                     ` Jeff Law
2018-05-02 17:04                       ` Jakub Jelinek
2018-05-03  9:55                       ` Nick Clifton
2018-05-30 23:18                         ` Jeff Law
2018-06-18 14:04                     ` Martin Jambor
2018-06-18 16:29                       ` Nick Clifton

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