diff mbox series

[fortran] New take on PR 82373

Message ID e3e1da07-0dce-d198-3694-7040bd2febe4@netcologne.de
State New
Headers show
Series [fortran] New take on PR 82373 | expand

Commit Message

Thomas Koenig Oct. 12, 2017, 6:21 p.m. UTC
Hello world,

after some thought, I think the PR can be fixed by something
far less invasive than my previous patch.

The new version of the patch simply issues an error for a
non-printable character (which should never be legal).
Anything else should be caught by other error reporting
routines.

OK for trunk?

Regards

	Thomas

2017-10-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/82372
         * fortran/scanner.c (last_error_char):  New global variable.
         (gfc_scanner_init_1): Set last_error_char to NULL.
         (gfc_gooble_whitespace): If a character not printable or
         not newline, issue an error.

2017-10-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/82372
         * gfortran.dg/illegal_char.f90: New test.

Comments

Steve Kargl Oct. 12, 2017, 7:26 p.m. UTC | #1
On Thu, Oct 12, 2017 at 08:21:46PM +0200, Thomas Koenig wrote:
> 
> after some thought, I think the PR can be fixed by something
> far less invasive than my previous patch.
> 
> The new version of the patch simply issues an error for a
> non-printable character (which should never be legal).
> Anything else should be caught by other error reporting
> routines.
> 
> OK for trunk?
> 

I like this patch much better than the last.  It's
ok with me, but you might want give 24 hours to let
the world rotate before committing (ie., allow others
to comment).
Thomas Koenig Oct. 15, 2017, 12:14 p.m. UTC | #2
Hi Steve,

> I like this patch much better than the last.  It's
> ok with me, but you might want give 24 hours to let
> the world rotate before committing (ie., allow others
> to comment)

Committed as r253768.  Thanks for the review!

I don't think it is worth backporting, so I'll close
the bug. If somebody thinks that we should indeed backport,
please let me know.

Regards

	Thomas
diff mbox series

Patch

Index: scanner.c
===================================================================
--- scanner.c	(Revision 253530)
+++ scanner.c	(Arbeitskopie)
@@ -80,6 +80,7 @@  static struct gfc_file_change
 size_t file_changes_cur, file_changes_count;
 size_t file_changes_allocated;
 
+static gfc_char_t *last_error_char;
 
 /* Functions dealing with our wide characters (gfc_char_t) and
    sequences of such characters.  */
@@ -269,6 +270,7 @@  gfc_scanner_init_1 (void)
   continue_line = 0;
 
   end_flag = 0;
+  last_error_char = NULL;
 }
 
 
@@ -1700,6 +1702,14 @@  gfc_gobble_whitespace (void)
     }
   while (gfc_is_whitespace (c));
 
+  if (!ISPRINT(c) && c != '\n' && last_error_char != gfc_current_locus.nextc)
+    {
+      char buf[20];
+      last_error_char = gfc_current_locus.nextc;
+      snprintf (buf, 20, "%2.2X", c);
+      gfc_error_now ("Invalid character 0x%s at %C", buf);
+    }
+
   gfc_current_locus = old_loc;
 }