Mercurial > octave
changeset 31502:b39bf92a2364
scanf: Reset failbit when reaching eof while scanning for whitespace (bug #62723).
* libinterp/corefcn/oct-stream.cc (DO_WHITESPACE_CONVERSION): The failbit is set
on a stream when "get" reaches the eof. Reset the failbit in this case to be
able to distinguish this case from "real" failures.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Tue, 22 Nov 2022 12:45:48 +0100 |
parents | 2d38bc5a35db |
children | 2a12350f9410 |
files | libinterp/corefcn/oct-stream.cc |
diffstat | 1 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/oct-stream.cc Mon Nov 21 19:56:25 2022 -0800 +++ b/libinterp/corefcn/oct-stream.cc Tue Nov 22 12:45:48 2022 +0100 @@ -4505,11 +4505,16 @@ { \ int c = std::istream::traits_type::eof (); \ \ + /* get all whitespace characters */ \ while (is && (c = is.get ()) != std::istream::traits_type::eof () \ && isspace (c)) \ { /* skip whitespace */ } \ \ - if (c != std::istream::traits_type::eof ()) \ + if (c == std::istream::traits_type::eof ()) \ + /* reset failbit at eof */ \ + is.clear (is.rdstate () & (~std::ios::failbit)); \ + else \ + /* put back non-whitespace character */ \ is.putback (c); \ } \ while (0)