From patchwork Sat Jan 11 17:13:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 309527 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 E27D82C0082 for ; Sun, 12 Jan 2014 04:14:17 +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=Cjlg/KxAl0/PMbSYhvbyl9g5VWZeWZRd10cRRUmtYPo wOPTdaxbTjpDaQ//D+60Nf+vR/E23aieU2NgoAdYvAIFMFcCzjwHpijUfWFNXL9A YbY+AeKOfBWYGWFZv81MM7TC2RSOb6FhkSHMn22hm5Mv5QRO8nzN+812oBJJAAQ4 = 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=luOBcDA/rRGxzsrxDbQRxZYpCuY=; b=WA2kGFl/XLpJxeFTe FdQ4ELfqKhN7YFXOHJRtZV+9wRG8Ycwqwky637dR9kmmoditL9otb2qwhXnVCW2T Fw/VufcCLLjgyW2Eh551d+qRuk6VUfVWjuwonA4dj4VkVRZaTkO5foDTePJHZvqs jVHiABJKE8QDh1Nu4WpSa+yfE4= Received: (qmail 30805 invoked by alias); 11 Jan 2014 17:14:03 -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 30781 invoked by uid 89); 11 Jan 2014 17:14:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mta41.charter.net Received: from mta41.charter.net (HELO mta41.charter.net) (216.33.127.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 11 Jan 2014 17:14:01 +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 <20140111171359.FHFK10143.mta41.charter.net@imp11>; Sat, 11 Jan 2014 12:13:59 -0500 Received: from pavilion.localdomain ([68.5.43.244]) by imp11 with smtp.charter.net id ChDy1n0065G55b005hDyvf; Sat, 11 Jan 2014 12:13:59 -0500 X-Authority-Analysis: v=2.0 cv=F7QP7ddN c=1 sm=1 a=mw+G4YjGptsaRR05zBLClw==:17 a=Pb0Ze0ZI5mYA:10 a=Y3k11qtu_LsA:10 a=yUnIBFQkZM0A:10 a=hOpmn2quAAAA:8 a=JBLfgZWCj6sA:10 a=mDV3o1hIAAAA:8 a=7bLjNRPdyNckKnsXRUoA:9 a=wPNLvfGTeEIA:10 a=doV9F6Je1px1f_xSQEIA:9 a=my4ptjvil3lW8TGq:21 a=Al8ty7PpX2aLqM5O:21 a=mw+G4YjGptsaRR05zBLClw==:117 X-Auth-id: anZkZWxpc2xlQGNoYXJ0ZXIubmV0 Message-ID: <52D17BCC.7060209@charter.net> Date: Sat, 11 Jan 2014 09:13:48 -0800 From: Jerry DeLisle User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: gfortran CC: gcc patches Subject: [Patch, libgfortran] PR59700 and PR59764 Misleading/buggy runtime error message The attached patch fixes both these bugs, combining Steve's patch and mine. Recent fixes of memory leaks placed the free_line before the generation of the error messages rather than after, The item_count which identifies the read list item involved with the error was getting cleared, resulting in a faulty error message. This is fixed by moving the free_line location to after the message string is created (before issuing the error still). The second issue is the variable item_count was being used for two separate purposes and collided in the case of read_logical. This was a known issue from several years ago. Fixed by adjusting the dtp structure just a bit. I used a spare bit for the expanded_read flag and then used the integer slot made available for a new variable line_buffer_pos. The new variable name is an accurate description of what it does, not confused with "item_count". Regression tested on x86-64. OK for trunk? I will add the test case from PR59700 to the test suite. Regards, Jerry 2014-01-10 Jerry DeLisle Steven G. Kargl PR libfortran/59700 PR libfortran/59764 * io/io.h (struct st_parameter_dt): Assign expanded_read flag to unused bit. Define new variable line_buffer_pos. * io/list_read.c (free_saved, next_char, l_push_char, read_logical, read_real): Replace use of item_count with line_buffer_pos for line_buffer look ahead. (read_logical, read_integer, parse_real, read_real, check_type): Adjust location of free_line to after generating error messages to retain the correct item count for the message. Index: io.h =================================================================== --- io.h (revision 206351) +++ io.h (working copy) @@ -430,7 +430,10 @@ typedef struct st_parameter_dt unsigned g0_no_blanks : 1; /* Used to signal use of free_format_data. */ unsigned format_not_saved : 1; - /* 14 unused bits. */ + /* A flag used to identify when a non-standard expanded namelist read + has occurred. */ + unsigned expanded_read : 1; + /* 13 unused bits. */ /* Used for ungetc() style functionality. Possible values are an unsigned char, EOF, or EOF - 1 used to mark the @@ -447,9 +450,8 @@ typedef struct st_parameter_dt char *line_buffer; struct format_data *fmt; namelist_info *ionml; - /* A flag used to identify when a non-standard expanded namelist read - has occurred. */ - int expanded_read; + /* Current position within the look-ahead line buffer. */ + int line_buffer_pos; /* Storage area for values except for strings. Must be large enough to hold a complex value (two reals) of the largest kind. */ Index: list_read.c =================================================================== --- list_read.c (revision 206351) +++ list_read.c (working copy) @@ -118,7 +118,7 @@ free_saved (st_parameter_dt *dtp) static void free_line (st_parameter_dt *dtp) { - dtp->u.p.item_count = 0; + dtp->u.p.line_buffer_pos = 0; dtp->u.p.line_buffer_enabled = 0; if (dtp->u.p.line_buffer == NULL) @@ -150,15 +150,15 @@ next_char (st_parameter_dt *dtp) { dtp->u.p.at_eol = 0; - c = dtp->u.p.line_buffer[dtp->u.p.item_count]; - if (c != '\0' && dtp->u.p.item_count < 64) + c = dtp->u.p.line_buffer[dtp->u.p.line_buffer_pos]; + if (c != '\0' && dtp->u.p.line_buffer_pos < 64) { - dtp->u.p.line_buffer[dtp->u.p.item_count] = '\0'; - dtp->u.p.item_count++; + dtp->u.p.line_buffer[dtp->u.p.line_buffer_pos] = '\0'; + dtp->u.p.line_buffer_pos++; goto done; } - dtp->u.p.item_count = 0; + dtp->u.p.line_buffer_pos = 0; dtp->u.p.line_buffer_enabled = 0; } @@ -639,7 +639,7 @@ l_push_char (st_parameter_dt *dtp, char c) if (dtp->u.p.line_buffer == NULL) dtp->u.p.line_buffer = xcalloc (SCRATCH_SIZE, 1); - dtp->u.p.line_buffer[dtp->u.p.item_count++] = c; + dtp->u.p.line_buffer[dtp->u.p.line_buffer_pos++] = c; } @@ -749,7 +749,7 @@ read_logical (st_parameter_dt *dtp, int length) { dtp->u.p.nml_read_error = 1; dtp->u.p.line_buffer_enabled = 1; - dtp->u.p.item_count = 0; + dtp->u.p.line_buffer_pos = 0; return; } @@ -757,14 +757,17 @@ read_logical (st_parameter_dt *dtp, int length) bad_logical: - free_line (dtp); - if (nml_bad_return (dtp, c)) - return; + { + free_line (dtp); + return; + } + free_saved (dtp); if (c == EOF) { + free_line (dtp); hit_eof (dtp); return; } @@ -772,6 +775,7 @@ read_logical (st_parameter_dt *dtp, int length) eat_line (dtp); snprintf (message, MSGLEN, "Bad logical value while reading item %d", dtp->u.p.item_count); + free_line (dtp); generate_error (&dtp->common, LIBERROR_READ_VALUE, message); return; @@ -912,9 +916,9 @@ read_integer (st_parameter_dt *dtp, int length) else if (c != '\n') eat_line (dtp); - free_line (dtp); snprintf (message, MSGLEN, "Bad integer for item %d in list input", dtp->u.p.item_count); + free_line (dtp); generate_error (&dtp->common, LIBERROR_READ_VALUE, message); return; @@ -1297,9 +1301,9 @@ parse_real (st_parameter_dt *dtp, void *buffer, in else if (c != '\n') eat_line (dtp); - free_line (dtp); snprintf (message, MSGLEN, "Bad floating point number for item %d", dtp->u.p.item_count); + free_line (dtp); generate_error (&dtp->common, LIBERROR_READ_VALUE, message); return 1; @@ -1405,9 +1409,9 @@ eol_4: else if (c != '\n') eat_line (dtp); - free_line (dtp); snprintf (message, MSGLEN, "Bad complex value in item %d of list input", dtp->u.p.item_count); + free_line (dtp); generate_error (&dtp->common, LIBERROR_READ_VALUE, message); } @@ -1769,7 +1773,7 @@ read_real (st_parameter_dt *dtp, void * dest, int { dtp->u.p.nml_read_error = 1; dtp->u.p.line_buffer_enabled = 1; - dtp->u.p.item_count = 0; + dtp->u.p.line_buffer_pos = 0; return; } @@ -1788,9 +1792,9 @@ read_real (st_parameter_dt *dtp, void * dest, int else if (c != '\n') eat_line (dtp); - free_line (dtp); snprintf (message, MSGLEN, "Bad real number in item %d of list input", dtp->u.p.item_count); + free_line (dtp); generate_error (&dtp->common, LIBERROR_READ_VALUE, message); } @@ -1805,11 +1809,10 @@ check_type (st_parameter_dt *dtp, bt type, int kin if (dtp->u.p.saved_type != BT_UNKNOWN && dtp->u.p.saved_type != type) { - free_line (dtp); snprintf (message, MSGLEN, "Read type %s where %s was expected for item %d", type_name (dtp->u.p.saved_type), type_name (type), dtp->u.p.item_count); - + free_line (dtp); generate_error (&dtp->common, LIBERROR_READ_VALUE, message); return 1; } @@ -1820,13 +1823,13 @@ check_type (st_parameter_dt *dtp, bt type, int kin if ((type != BT_COMPLEX && dtp->u.p.saved_length != kind) || (type == BT_COMPLEX && dtp->u.p.saved_length != kind*2)) { - free_line (dtp); snprintf (message, MSGLEN, "Read kind %d %s where kind %d is required for item %d", type == BT_COMPLEX ? dtp->u.p.saved_length / 2 : dtp->u.p.saved_length, type_name (dtp->u.p.saved_type), kind, dtp->u.p.item_count); + free_line (dtp); generate_error (&dtp->common, LIBERROR_READ_VALUE, message); return 1; }