re PR fortran/67367 (Program crashes on READ(IOSTAT=IOS, ...) on directory OPEN(...
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 29 Aug 2015 15:38:39 +0000 (15:38 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 29 Aug 2015 15:38:39 +0000 (15:38 +0000)
2015-08-29 Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/67367
* io/unix.c (buf_read): Check for error condition and if found
return the error code.

From-SVN: r227320

libgfortran/ChangeLog
libgfortran/io/unix.c

index 62db347978f6ec8578e413305f1802ef78fb7138..d08f050eb31b434913c18681f1852ec321f3e884 100644 (file)
@@ -1,3 +1,9 @@
+2015-08-29 Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/67367
+       * io/unix.c (buf_read): Check for error condition and if found
+       return the error code.
+
 2015-08-29  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        * acinclude.m4: Remove LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT.
index aa2feabebf0ab4c1d2a498677ff8c687cfa421e2..fd5f2779021c0aa2d1ded37742ed723688b8c3c6 100644 (file)
@@ -518,16 +518,26 @@ buf_read (unix_stream * s, void * buf, ssize_t nbyte)
       if (to_read <= BUFFER_SIZE/2)
         {
           did_read = raw_read (s, s->buffer, BUFFER_SIZE);
-          s->physical_offset += did_read;
-          s->active = did_read;
-          did_read = (did_read > to_read) ? to_read : did_read;
-          memcpy (p, s->buffer, did_read);
+         if (likely (did_read >= 0))
+           {
+             s->physical_offset += did_read;
+             s->active = did_read;
+             did_read = (did_read > to_read) ? to_read : did_read;
+             memcpy (p, s->buffer, did_read);
+           }
+         else
+           return did_read;
         }
       else
         {
           did_read = raw_read (s, p, to_read);
-          s->physical_offset += did_read;
-          s->active = 0;
+         if (likely (did_read >= 0))
+           {
+             s->physical_offset += did_read;
+             s->active = 0;
+           }
+         else
+           return did_read;
         }
       nbyte = did_read + nread;
     }