From patchwork Wed Sep 28 05:15:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 675955 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3skQsH3ndgz9s9Y for ; Wed, 28 Sep 2016 15:16:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=xA0zHehp; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=L4HVzkr9ooergw/OWm5ARu6e4DViAMwLxrkO6HhKAwABaioTp5 kodIJWu5CpLcJe6flgQqnyMe4XOjT9/aojHYvBk04VLvaRwO1GFXBx/3jqX7NNkZ 7HQFvbRbbtN1xg65EuXdefByue07wqa8TGgSlcSYI/eoxho2UEzww3I6Q= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=LaNcqMgc1SJhJvhW4kB0orf5+es=; b=xA0zHehpNInJ8ex4k3dy OP+j1bmTdrn8QCcTTSwz0GLsSGuTp8NPZvaX2c2hNlsyIPIRKZs2b+3+Y6qyNhzF VFZhG2Psri7nnkuFw22NAgNDVyM9pEZNUxslBjU2WfsLFmpIM9e4QM/MomwpVgik NCJG77x765fm1CTwFetdZg0= Received: (qmail 123133 invoked by alias); 28 Sep 2016 05:15:53 -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 123110 invoked by uid 89); 28 Sep 2016 05:15:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:charter X-Spam-User: qpsmtpd, 2 recipients X-HELO: mtaout005-public.msg.strl.va.charter.net Received: from mtaout005-public.msg.strl.va.charter.net (HELO mtaout005-public.msg.strl.va.charter.net) (68.114.190.30) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Sep 2016 05:15:46 +0000 Received: from impout002 ([68.114.189.17]) by mtaout005.msg.strl.va.charter.net (InterMail vM.9.00.023.01 201-2473-194) with ESMTP id <20160928051543.NMIY7356.mtaout005.msg.strl.va.charter.net@impout002>; Wed, 28 Sep 2016 00:15:43 -0500 Received: from amda8.localdomain ([96.41.215.23]) by impout002 with charter.net id otFg1t00E0Wrkg001tFhAK; Wed, 28 Sep 2016 00:15:43 -0500 X-Authority-Analysis: v=2.1 cv=aMB+qNNm c=1 sm=1 tr=0 a=salB9WdMPIDduBH7JsZfrA==:117 a=salB9WdMPIDduBH7JsZfrA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=mDV3o1hIAAAA:8 a=kwc66pmF1HdKM5zsGqoA:9 a=QEXdDO2ut3YA:10 a=H1NhVoc8KKwA:10 a=oyC1OH84-mzn2WOSeaMA:9 a=bnyFSqgVoMsKpKSvIlUA:9 a=AIMc_s0aOUsA:10 a=_FVE-zBwftR9WsbkzFJk:22 X-Auth-id: anZkZWxpc2xlQGNoYXJ0ZXIubmV0 To: "fortran@gcc.gnu.org" Cc: GCC Patches From: Jerry DeLisle Subject: [patch, libgfortran] PR77707 formatted direct access: nextrec off by one Message-ID: <60e46aee-a8c2-188e-2b65-ff2e83f794e0@charter.net> Date: Tue, 27 Sep 2016 22:15:40 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 I plan to commit the attached patch in the next few days. Fairly simple. Regression tested on x86-64. Regards, Jerry 2016-09-27 Jerry DeLisle PR libgfortran/77707 io/transfer.c (next_record): Flush before calculating next_record. Correctly calculate. diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 6009c123..902c0201 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -3720,6 +3720,8 @@ next_record (st_parameter_dt *dtp, int done) else next_record_w (dtp, done); + fbuf_flush (dtp->u.p.current_unit, dtp->u.p.mode); + if (!is_stream_io (dtp)) { /* Since we have changed the position, set it to unspecified so @@ -3733,8 +3735,8 @@ next_record (st_parameter_dt *dtp, int done) fp = stell (dtp->u.p.current_unit->s); /* Calculate next record, rounding up partial records. */ dtp->u.p.current_unit->last_record = - (fp + dtp->u.p.current_unit->recl - 1) / - dtp->u.p.current_unit->recl; + (fp + dtp->u.p.current_unit->recl) / + dtp->u.p.current_unit->recl - 1; } else dtp->u.p.current_unit->last_record++; @@ -3743,7 +3745,6 @@ next_record (st_parameter_dt *dtp, int done) if (!done) pre_position (dtp); - fbuf_flush (dtp->u.p.current_unit, dtp->u.p.mode); smarkeor (dtp->u.p.current_unit->s); }