From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23774 invoked by alias); 22 Dec 2010 15:25:41 -0000 Received: (qmail 23755 invoked by uid 22791); 22 Dec 2010 15:25:40 -0000 X-SWARE-Spam-Status: No, hits=-2.2 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) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Dec 2010 15:25:35 +0000 Received: from kpbe16.cbf.corp.google.com (kpbe16.cbf.corp.google.com [172.25.105.80]) by smtp-out.google.com with ESMTP id oBMFPXqx008372 for ; Wed, 22 Dec 2010 07:25:33 -0800 Received: from pzk27 (pzk27.prod.google.com [10.243.19.155]) by kpbe16.cbf.corp.google.com with ESMTP id oBMFPWqV015804 for ; Wed, 22 Dec 2010 07:25:32 -0800 Received: by pzk27 with SMTP id 27so1545181pzk.14 for ; Wed, 22 Dec 2010 07:25:32 -0800 (PST) Received: by 10.142.128.1 with SMTP id a1mr5680108wfd.282.1293031531891; Wed, 22 Dec 2010 07:25:31 -0800 (PST) Received: from coign.google.com ([67.218.105.75]) by mx.google.com with ESMTPS id e14sm9273701wfg.8.2010.12.22.07.25.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 22 Dec 2010 07:25:31 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't crash if array length is invalid const Date: Wed, 22 Dec 2010 16:05:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2010-12/txt/msg01703.txt.bz2 --=-=-= Content-length: 207 This patch to the Go frontend avoids a crash if the length of an array is a const which turns out to be invalid. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=foo.patch Content-Description: invalid Content-length: 1090 diff -r 08ce2cd2cdcd go/expressions.cc --- a/go/expressions.cc Wed Dec 22 07:08:44 2010 -0800 +++ b/go/expressions.cc Wed Dec 22 07:21:09 2010 -0800 @@ -9095,7 +9095,11 @@ this->report_error(_("slice end must be integer")); Array_type* array_type = this->array_->type()->array_type(); - gcc_assert(array_type != NULL); + if (array_type == NULL) + { + gcc_assert(this->array_->type()->is_error_type()); + return; + } unsigned int int_bits = Type::lookup_integer_type("int")->integer_type()->bits(); @@ -10936,7 +10940,14 @@ tree Open_array_construction_expression::do_get_tree(Translate_context* context) { - Type* element_type = this->type()->array_type()->element_type(); + Array_type* array_type = this->type()->array_type(); + if (array_type == NULL) + { + gcc_assert(this->type()->is_error_type()); + return error_mark_node; + } + + Type* element_type = array_type->element_type(); tree element_type_tree = element_type->get_tree(context->gogo()); if (element_type_tree == error_mark_node) return error_mark_node; --=-=-=--