OSDN Git Service

PR target/23556
[pf3gnuchains/gcc-fork.git] / libgfortran / io / read.c
index 4cfad8d..e37224d 100644 (file)
@@ -24,8 +24,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with Libgfortran; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 #include "config.h"
@@ -124,24 +124,36 @@ convert_real (void *dest, const char *buffer, int length)
   switch (length)
     {
     case 4:
-      *((GFC_REAL_4 *) dest) =
+      {
+       GFC_REAL_4 tmp =
 #if defined(HAVE_STRTOF)
-       strtof (buffer, NULL);
+         strtof (buffer, NULL);
 #else
-       (GFC_REAL_4) strtod (buffer, NULL);
+         (GFC_REAL_4) strtod (buffer, NULL);
 #endif
+       memcpy (dest, (void *) &tmp, length);
+      }
       break;
     case 8:
-      *((GFC_REAL_8 *) dest) = strtod (buffer, NULL);
+      {
+       GFC_REAL_8 tmp = strtod (buffer, NULL);
+       memcpy (dest, (void *) &tmp, length);
+      }
       break;
 #if defined(HAVE_GFC_REAL_10) && defined (HAVE_STRTOLD)
     case 10:
-      *((GFC_REAL_10 *) dest) = strtold (buffer, NULL);
+      {
+       GFC_REAL_10 tmp = strtold (buffer, NULL);
+       memcpy (dest, (void *) &tmp, length);
+      }
       break;
 #endif
 #if defined(HAVE_GFC_REAL_16) && defined (HAVE_STRTOLD)
     case 16:
-      *((GFC_REAL_16 *) dest) = strtold (buffer, NULL);
+      {
+       GFC_REAL_16 tmp = strtold (buffer, NULL);
+       memcpy (dest, (void *) &tmp, length);
+      }
       break;
 #endif
     default:
@@ -691,24 +703,46 @@ read_f (fnode * f, char *dest, int length)
   p++;
   w--;
 
-  while (w > 0)
+  if (g.blank_status == BLANK_UNSPECIFIED) /* Normal processing of exponent */
     {
-      if (*p == ' ')
+      while (w > 0 && isdigit (*p))
         {
-          if (g.blank_status == BLANK_ZERO) *p = '0';
-          if (g.blank_status == BLANK_NULL)
+          exponent = 10 * exponent + *p - '0';
+          p++;
+          w--;
+        }
+        
+      /* Only allow trailing blanks */
+
+      while (w > 0)
+        {
+          if (*p != ' ')
+         goto bad_float;
+          p++;
+          w--;
+        }
+    }    
+  else  /* BZ or BN status is enabled */
+    {
+      while (w > 0)
+        {
+          if (*p == ' ')
             {
-              p++;
-              w--;
-              continue;
+              if (g.blank_status == BLANK_ZERO) *p = '0';
+              if (g.blank_status == BLANK_NULL)
+                {
+                  p++;
+                  w--;
+                  continue;
+                }
             }
+          else if (!isdigit (*p))
+            goto bad_float;
+
+          exponent = 10 * exponent + *p - '0';
+          p++;
+          w--;
         }
-      if (!isdigit (*p))
-        goto bad_float;
-        
-      exponent = 10 * exponent + *p - '0';
-      p++;
-      w--;
     }
 
   exponent = exponent * exponent_sign;
@@ -784,12 +818,14 @@ read_f (fnode * f, char *dest, int length)
 void
 read_x (fnode * f)
 {
-  int n, m;
+  int n;
 
   n = f->u.n;
-  m = (int)current_unit->bytes_left;
-  if (f->format == FMT_X)
-    n = (n > m) ? m : n;
-  if (n)
+
+  if ((current_unit->flags.pad == PAD_NO || is_internal_unit ())
+      && current_unit->bytes_left < n)
+    n = current_unit->bytes_left;
+
+  if (n > 0)
     read_block (&n);
 }