From patchwork Tue Dec 21 23:48:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 76346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id ECA74B70A3 for ; Wed, 22 Dec 2010 10:49:04 +1100 (EST) Received: (qmail 13271 invoked by alias); 21 Dec 2010 23:48:59 -0000 Received: (qmail 13257 invoked by uid 22791); 21 Dec 2010 23:48:58 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 21 Dec 2010 23:48:53 +0000 Received: from kpbe18.cbf.corp.google.com (kpbe18.cbf.corp.google.com [172.25.105.82]) by smtp-out.google.com with ESMTP id oBLNmoXg006408 for ; Tue, 21 Dec 2010 15:48:50 -0800 Received: from pvg7 (pvg7.prod.google.com [10.241.210.135]) by kpbe18.cbf.corp.google.com with ESMTP id oBLNmgx3001614 for ; Tue, 21 Dec 2010 15:48:44 -0800 Received: by pvg7 with SMTP id 7so1077717pvg.36 for ; Tue, 21 Dec 2010 15:48:42 -0800 (PST) Received: by 10.142.134.11 with SMTP id h11mr5023341wfd.206.1292975322366; Tue, 21 Dec 2010 15:48:42 -0800 (PST) Received: from coign.google.com (dhcp-172-22-122-207.mtv.corp.google.com [172.22.122.207]) by mx.google.com with ESMTPS id w42sm8240226wfh.15.2010.12.21.15.48.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 21 Dec 2010 15:48:41 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't warn about []int of string with NUL bytes Date: Tue, 21 Dec 2010 15:48:40 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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; }