# HG changeset patch # User Arun Giridhar # Date 1669394000 18000 # Node ID 85a073f7c5f9ac11e8698e1ab7542c4728b7ce57 # Parent 8459f7f216790398d2c0e3e26926958472e84b94# Parent 2f08a53e0a23e24a7220162f32011cd4f53ab20c maint: Merge away extra head diff -r 8459f7f21679 -r 85a073f7c5f9 libinterp/corefcn/oct-stream.cc --- a/libinterp/corefcn/oct-stream.cc Fri Nov 25 11:32:48 2022 -0500 +++ b/libinterp/corefcn/oct-stream.cc Fri Nov 25 11:33:20 2022 -0500 @@ -4442,16 +4442,19 @@ case 'G': { is >> std::ws; // skip through whitespace and advance stream pointer - std::streampos pos = is.tellg (); - - ref = read_value (is); - - std::ios::iostate status = is.rdstate (); - if (status & std::ios::failbit) + if (is.good ()) { - is.clear (); - is.seekg (pos); - is.setstate (status & ~std::ios_base::eofbit); + std::streampos pos = is.tellg (); + + ref = read_value (is); + + std::ios::iostate status = is.rdstate (); + if (status & std::ios::failbit) + { + is.clear (); + is.seekg (pos); + is.setstate (status & ~std::ios_base::eofbit); + } } } break; diff -r 8459f7f21679 -r 85a073f7c5f9 liboctave/util/lo-utils.cc --- a/liboctave/util/lo-utils.cc Fri Nov 25 11:32:48 2022 -0500 +++ b/liboctave/util/lo-utils.cc Fri Nov 25 11:33:20 2022 -0500 @@ -215,7 +215,10 @@ { char c2 = is.get (); if (c2 == 'f' || c2 == 'F') - val = std::numeric_limits::infinity (); + { + val = std::numeric_limits::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::quiet_NaN (); + { + val = std::numeric_limits::quiet_NaN (); + is.peek (); // Potentially set EOF bit + } else { val = numeric_limits::NA (); @@ -290,7 +296,7 @@ is >> val; } - if (neg && ! is.fail ()) + if (neg && ! math::isnan (val) && ! is.fail ()) val = -val; } break; diff -r 8459f7f21679 -r 85a073f7c5f9 test/io.tst --- a/test/io.tst Fri Nov 25 11:32:48 2022 -0500 +++ b/test/io.tst Fri Nov 25 11:33:20 2022 -0500 @@ -514,7 +514,7 @@ %! assert (pos, 5); ## Test NaN at EOF -%!test <63383> +%!test <*63383> %! [val, count, msg, pos] = sscanf ('2 3 n', '%f'); %! assert (val, [2; 3]); %! assert (count, 2); @@ -550,7 +550,7 @@ %! assert (pos, 10); ## Test Inf at EOF -%!test <63383> +%!test <*63383> %! [val, count, msg, pos] = sscanf ('2 3 i', '%f'); %! assert (val, [2; 3]); %! assert (count, 2); @@ -611,6 +611,60 @@ %! assert (msg, 'sscanf: format failed to match'); %! assert (pos, 5); +## Test '+' at EOF +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('2 3 +', '%d'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 +', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); + +## Test '+' within string +%!test <63383> +%! [val, count, msg, pos] = sscanf ('1 2 + 3', '%d'); +%! assert (val, [1; 2]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('1 2 + 3', '%f'); +%! assert (val, [1; 2]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); + +%## Test +NA, -NA, +NAN, -NAN +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('+NA -NA 1 +NAN -NAN', '%f'); +%! assert (val, [NA; NA; 1; NaN; NaN]); +%! assert (count, 5); +%! assert (msg, ''); +%! assert (pos, 20); +%! [val, count, msg, pos] = sscanf ('-NA', '%f'); +%! assert (val, NA); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 4); +%! [val, count, msg, pos] = sscanf ('+NA', '%f'); +%! assert (val, NA); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 4); +%! [val, count, msg, pos] = sscanf ('-NaN', '%f'); +%! assert (val, NaN); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('+NaN', '%f'); +%! assert (val, NaN); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 5); + %!test %! [a, b, c] = sscanf ("1.2 3 foo", "%f%d%s", "C"); %! [v1, c1, m1] = sscanf ("1 2 3 4 5 6", "%d");