]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: complain about invalid whitespace chars
authorRobert Griesemer <gri@golang.org>
Mon, 19 Nov 2012 17:09:04 +0000 (09:09 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 19 Nov 2012 17:09:04 +0000 (09:09 -0800)
Fixes #4405.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/6855060

src/cmd/gc/lex.c
test/fixedbugs/issue4405.go [new file with mode: 0644]

index 1031320a0126df756ad4982b6157623547ae12e4..ad8bdebf036174404474310115ba1ac16b5d6289 100644 (file)
@@ -99,7 +99,7 @@ yy_isdigit(int c)
 static int
 yy_isspace(int c)
 {
-       return c >= 0 && c <= 0xFF && isspace(c);
+       return c == ' ' || c == '\t' || c == '\n' || c == '\r';
 }
 
 static int
@@ -790,12 +790,8 @@ static int
 isfrog(int c)
 {
        // complain about possibly invisible control characters
-       if(c < 0)
-               return 1;
        if(c < ' ') {
-               if(c == '\n' || c== '\r' || c == '\t')  // good white space
-                       return 0;
-               return 1;
+               return !yy_isspace(c);  // exclude good white space
        }
        if(0x7f <= c && c <= 0xa0)      // DEL, unicode block including unbreakable space.
                return 1;
diff --git a/test/fixedbugs/issue4405.go b/test/fixedbugs/issue4405.go
new file mode 100644 (file)
index 0000000..c0d8085
--- /dev/null
@@ -0,0 +1,15 @@
+// errorcheck
+
+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+const (
+       _ = iota
+       _\a // ERROR "illegal character"
+       _\b  // ERROR "illegal character"
+       _\v  // ERROR "illegal character"
+       _\f  // ERROR "illegal character"
+)