From patchwork Mon Apr 1 18:33:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 232787 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 123232C011E for ; Tue, 2 Apr 2013 05:34:20 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=YKYqilthhr9OfCgMd0SHAdcoVSJelaRDLBlFLlqDo8I mQKWoxNuVa79xF/DNbbi/ENdRXbe/GvFihhbT1sD7UrdrCQXz+StgxNlVgx2PJqG D3RRVIxPsmmMYj5OUTRH70sJ63t6chxwYsQWhRuRr1Hfm4FAZo33LPUrf7rJ5qbQ = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=h11nLa5EFGlXqsrd3BqZtcygRcg=; b=QSY/Ele7FBZCl1G+G bcJG5MWqxh3VObnkZ9CamcEaL70crPfDzRnN/BFQnWztz3OGE6MI9ipOyzoVFC00 VF5GwMpEsiUrnHXU8UvR2D/tpWOdpR2HmmzlZ80i0ZB0L0ASsLUbA//fhPiY6uGx DwhUWDAduG4C7/g/4NiujVYBuI= Received: (qmail 27548 invoked by alias); 1 Apr 2013 18:33:59 -0000 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 Received: (qmail 27504 invoked by uid 89); 1 Apr 2013 18:33:49 -0000 X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_CP autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mta41.charter.net (HELO mta41.charter.net) (216.33.127.83) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 01 Apr 2013 18:33:46 +0000 Received: from imp11 ([10.20.200.11]) by mta41.charter.net (InterMail vM.8.01.05.02 201-2260-151-103-20110920) with ESMTP id <20130401183344.CYEY10143.mta41.charter.net@imp11>; Mon, 1 Apr 2013 14:33:44 -0400 Received: from quava.localdomain ([72.194.70.222]) by imp11 with smtp.charter.net id JiZj1l00D4nkj6o05iZjPQ; Mon, 01 Apr 2013 14:33:44 -0400 X-Authority-Analysis: v=2.0 cv=dIr+A5lb c=1 sm=1 a=L8sds5GVmE6e+zP2dgJA1w==:17 a=VW8mOq7NZXgA:10 a=dP5H6h4XIRMA:10 a=yUnIBFQkZM0A:10 a=hOpmn2quAAAA:8 a=KWEd8_l0_8sA:10 a=mDV3o1hIAAAA:8 a=AdY_v2BUkojmVpTMIUwA:9 a=wPNLvfGTeEIA:10 a=3_Qne1AKm0B5BR2SmM8A:9 a=o7eybTWKcH9TeLeczgoA:9 a=L8sds5GVmE6e+zP2dgJA1w==:117 X-Auth-id: anZkZWxpc2xlQGNoYXJ0ZXIubmV0 Message-ID: <5159D307.1040405@charter.net> Date: Mon, 01 Apr 2013 11:33:43 -0700 From: Jerry DeLisle User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 MIME-Version: 1.0 To: gfortran CC: gcc patches Subject: [patch, libfortran] PR56660 Fails to read NAMELIST with certain form array syntax X-Virus-Found: No Hi all, When doing namelist reads, nml_read_obj calls itself recursively to read through arrays. Short lists are allowed so we have to have a way to detect if we have a short read or a real error. We do this by flagging errors and then backing out of the read and checking to see if what we error-ed on was a valid object name rather than data. This is problematic for reading strings or logicals, since the data can look like names. To resolve the problem, we use a line_buffer to hold reads as we look ahead and if we find an error we rewind, bail out of the read, and proceed to the next read cycle which looks for an object name followed by an "=" sign. With this particular bug, nml_read_obj was clearing the error flag itself with the read so that rather then bailing out, it tried to continue reading data until it was done, then the subsequent read failed looking for a valid name, which had been passed by. The problem is resolved by moving the error flag reset outside nml_read_obj just before the call to nml_read_obj. Also, we test the flag on entering nml_read_obj, and if it is set, we bail out right away, a do nothing, until the parent nml_read_obj finishes its loops. Regression tested on x86-64. Test case attached. OK for trunk? Jerry 2013-04-01 Jerry DeLisle PR libfortran/56660 * io/list_read.c (nml_read_obj): Do not reset the read error flag inside nml_read_obj. If the read error flag is found set just exit. Fix some whitespace on comments. (nml_read_obj_data): Reset the read error flag before the first call to nml_read_object. Index: list_read.c =================================================================== --- list_read.c (revision 197290) +++ list_read.c (working copy) @@ -2490,9 +2490,9 @@ nml_read_obj (st_parameter_dt *dtp, namelist_info size_t obj_name_len; void * pdata; - /* This object not touched in name parsing. */ - - if (!nl->touched) + /* If we have encountered a previous read error or this object has not been + touched in name parsing, just return. */ + if (dtp->u.p.nml_read_error || !nl->touched) return true; dtp->u.p.repeat_count = 0; @@ -2532,10 +2532,8 @@ nml_read_obj (st_parameter_dt *dtp, namelist_info - GFC_DESCRIPTOR_LBOUND(nl,dim)) * GFC_DESCRIPTOR_STRIDE(nl,dim) * nl->size); - /* Reset the error flag and try to read next value, if - dtp->u.p.repeat_count=0 */ + /* If we are finished with the repeat count, try to read next value. */ - dtp->u.p.nml_read_error = 0; nml_carry = 0; if (--dtp->u.p.repeat_count <= 0) { @@ -2564,8 +2562,8 @@ nml_read_obj (st_parameter_dt *dtp, namelist_info break; case BT_REAL: - /* Need to copy data back from the real location to the temp in order - to handle nml reads into arrays. */ + /* Need to copy data back from the real location to the temp in + order to handle nml reads into arrays. */ read_real (dtp, pdata, len); memcpy (dtp->u.p.value, pdata, dlen); break; @@ -3022,6 +3020,7 @@ get_name: nl = first_nl; } + dtp->u.p.nml_read_error = 0; if (!nml_read_obj (dtp, nl, 0, pprev_nl, nml_err_msg, nml_err_msg_size, clow, chigh)) goto nml_err_ret;