Patchwork Go patch committed: Don't warn about []int of string with NUL bytes

login
register
mail settings
Submitter Ian Taylor
Date Dec. 21, 2010, 11:48 p.m.
Message ID <mcrwrn2k7qf.fsf@google.com>
Download mbox | patch
Permalink /patch/76346/
State New
Headers show

Comments

Ian Taylor - Dec. 21, 2010, 11:48 p.m.
This patch to the Go frontend turns off an incorrect warning about using
[]int to convert a string with NUL bytes to Unicode code points.  We
want to reject NUL bytes in input files but not in strings.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r ca35ad3a10c6 go/lex.cc
--- a/go/lex.cc	Tue Dec 21 15:33:16 2010 -0800
+++ b/go/lex.cc	Tue Dec 21 15:44:58 2010 -0800
@@ -742,12 +742,7 @@ 
 Lex::fetch_char(const char* p, unsigned int* value)
 {
   unsigned char c = *p;
-  if (c == 0)
-    {    
-      *value = 0xfffd;
-      return 0;
-    }
-  else if (c <= 0x7f)
+  if (c <= 0x7f)
     {
       *value = c;
       return 1;
@@ -812,13 +807,19 @@ 
 			   bool* issued_error)
 {
   *issued_error = false;
+
+  if (*p == '\0')
+    {
+      error_at(this->location(), "invalid NUL byte");
+      *issued_error = true;
+      *value = 0;
+      return p + 1;
+    }
+
   int adv = Lex::fetch_char(p, value);
   if (adv == 0)
     {
-      if (*p == '\0')
-	error_at(this->location(), "invalid NUL byte");
-      else
-	error_at(this->location(), "invalid UTF-8 encoding");
+      error_at(this->location(), "invalid UTF-8 encoding");
       *issued_error = true;
       return p + 1;
     }