This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, libgfortran] PR38097 I/O with blanks in exponent fails; BN and BZ


Attached is a revised patch and test case. Tobias (via IRC) pointed out some additional troublesome cases. Turns out they were actually other bugs. Some initializations were not being done correctly.

This patch fixes those and cleans up the code a bit.

Regression tested on x86-64-Gnu-Linux?

OK for trunk?

Jerry

2008-11-16 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR libfortran/38097
	* io/read.c (read_f): Initialize exponent. Fix comment. Set loop
	conditions for BZ/BN.
	* io/unit.c (get_internal_unit): Initialize flags.blank.
	* io/transfer.c (data_transfer_init): Fix whitespace.
c     { dg-do run }
c     PR38097 I/O with blanks in exponent fails; BN edit descriptor
c     Test case derived from reporter.
      character(11)  :: a = ' 2.  3 e+ 3'
      character(11)  :: b = ' 2.003 e+ 3'
      character(11)  :: c = ' 2.002 e+1 '
      real :: f

      f = 0.0
      read (a,'(BZ,E11.0)') f
      if (f .ne. 2003.0) call abort
      f = 0.0
      read (a,'(BN,E11.0)') f
      if (f .ne. 2300.0) call abort
      f = 0.0
      read (b,'(BN,E11.0)') f
      if (f .ne. 2003.0) call abort
      f = 0.0
      read (c,'(E11.0)') f
      if (f .ne. 2.0020) call abort
      f = 0.0
      read (c,'(BZ,E11.0)') f
      if (f .ne. 2.002e10) call abort

      end
c     end of program

Index: read.c
===================================================================
--- read.c	(revision 141893)
+++ read.c	(working copy)
@@ -956,14 +956,9 @@ read_f (st_parameter_dt *dtp, const fnod
      of the exponent in order to take account of the scale factor and
      the d parameter before explict conversion takes place. */
  exp2:
-  if (!isdigit (*p))
-    goto bad_float;
-
-  exponent = *p - '0';
-  p++;
-  w--;
-
-  if (dtp->u.p.blank_status == BLANK_UNSPECIFIED) /* Normal processing of exponent */
+  /* Normal processing of exponent */
+  exponent = 0;
+  if (dtp->u.p.blank_status == BLANK_UNSPECIFIED)
     {
       while (w > 0 && isdigit (*p))
         {
@@ -984,7 +979,7 @@ read_f (st_parameter_dt *dtp, const fnod
     }    
   else  /* BZ or BN status is enabled */
     {
-      while (w > 0)
+      while (w > 0 && (isdigit (*p) || *p == ' '))
         {
           if (*p == ' ')
             {
Index: unit.c
===================================================================
--- unit.c	(revision 141893)
+++ unit.c	(working copy)
@@ -437,6 +437,7 @@ get_internal_unit (st_parameter_dt *dtp)
 
   iunit->flags.access = ACCESS_SEQUENTIAL;
   iunit->flags.action = ACTION_READWRITE;
+  iunit->flags.blank = BLANK_UNSPECIFIED;
   iunit->flags.form = FORM_FORMATTED;
   iunit->flags.pad = PAD_YES;
   iunit->flags.status = STATUS_UNSPECIFIED;
@@ -448,7 +449,6 @@ get_internal_unit (st_parameter_dt *dtp)
   /* Initialize the data transfer parameters.  */
 
   dtp->u.p.advance_status = ADVANCE_YES;
-  dtp->u.p.blank_status = BLANK_UNSPECIFIED;
   dtp->u.p.seen_dollar = 0;
   dtp->u.p.skips = 0;
   dtp->u.p.pending_spaces = 0;
Index: transfer.c
===================================================================
--- transfer.c	(revision 141893)
+++ transfer.c	(working copy)
@@ -2102,7 +2102,7 @@ data_transfer_init (st_parameter_dt *dtp
   
   if (dtp->u.p.blank_status == BLANK_UNSPECIFIED)
 	dtp->u.p.blank_status = dtp->u.p.current_unit->flags.blank;
-  
+
   /* Check the delim mode.  */
   dtp->u.p.current_unit->delim_status
 	= !(cf & IOPARM_DT_HAS_DELIM) ? DELIM_UNSPECIFIED :

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]