+2017-12-16 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ PR libgfortran/81937
+ * io/list_read.c (next_char_internal): Don't attempt to read
+ from the internal unit stream if no bytes are left. Decrement
+ bytes_left in the right place.
+
2017-12-12 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/78549
}
/* Get the next character and handle end-of-record conditions. */
-
- if (is_char4_unit(dtp)) /* Check for kind=4 internal unit. */
- length = sread (dtp->u.p.current_unit->s, &c, 1);
+ if (likely (dtp->u.p.current_unit->bytes_left > 0))
+ {
+ if (unlikely (is_char4_unit(dtp))) /* Check for kind=4 internal unit. */
+ length = sread (dtp->u.p.current_unit->s, &c, 1);
+ else
+ {
+ char cc;
+ length = sread (dtp->u.p.current_unit->s, &cc, 1);
+ c = cc;
+ }
+ }
else
- {
- char cc;
- length = sread (dtp->u.p.current_unit->s, &cc, 1);
- c = cc;
- }
+ length = 0;
if (unlikely (length < 0))
{
generate_error (&dtp->common, LIBERROR_INTERNAL_UNIT, NULL);
return '\0';
}
- dtp->u.p.current_unit->bytes_left--;
}
else
{
dtp->u.p.at_eof = 1;
}
}
+ dtp->u.p.current_unit->bytes_left--;
done:
dtp->u.p.at_eol = (c == '\n' || c == EOF);