Mercurial > octave
diff liboctave/util/lo-utils.cc @ 31542:2f08a53e0a23
Fix scanf handling of exceptional values (NA, NaN, Inf) at EOF (bug #63383)
* oct-stream.cc (octave_scan): After skipping whitespace, check stream with
is.good() before proceeding to read a value.
* lo-utils.cc (read_inf_nan_na): Use is.peek() after successfully reading Inf
or NaN to possibly set EOF bit.
* lo-utils.cc (read_fp_value): Add extra test that value is not NA or NaN
before changing it to -value when negative '-' character present.
* io.tst: Mark fixed BIST tests with '*' regression marker.
Add BIST tests for exceptional '+' character and for +/-NA, +/-NaN.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 25 Nov 2022 08:30:30 -0800 |
parents | d006285b7509 |
children | dfa5d9c3ae72 |
line wrap: on
line diff
--- a/liboctave/util/lo-utils.cc Thu Nov 24 16:16:52 2022 -0500 +++ b/liboctave/util/lo-utils.cc Fri Nov 25 08:30:30 2022 -0800 @@ -215,7 +215,10 @@ { char c2 = is.get (); if (c2 == 'f' || c2 == 'F') - val = std::numeric_limits<T>::infinity (); + { + val = std::numeric_limits<T>::infinity (); + is.peek (); // Potentially set EOF bit + } else is.setstate (std::ios::failbit); } @@ -231,7 +234,10 @@ { char c2 = is.get (); if (c2 == 'n' || c2 == 'N') - val = std::numeric_limits<T>::quiet_NaN (); + { + val = std::numeric_limits<T>::quiet_NaN (); + is.peek (); // Potentially set EOF bit + } else { val = numeric_limits<T>::NA (); @@ -290,7 +296,7 @@ is >> val; } - if (neg && ! is.fail ()) + if (neg && ! math::isnan (val) && ! is.fail ()) val = -val; } break;