Browse Source

Avoid input stream fail state when reading number at EOF.

istream::get() puts the stream in fail state when trying to read at
EOF. This is best avoided by first peek()ing what is available.
master
Richard Kreckel 13 years ago
parent
commit
4985c8a789
  1. 4
      README
  2. 2
      doc/cln.texi
  3. 4
      src/base/cl_free.cc
  4. 9
      src/complex/input/cl_N_read_stream.cc
  5. 9
      src/float/input/cl_F_read_stream.cc
  6. 9
      src/integer/input/cl_I_read_stream.cc
  7. 9
      src/rational/input/cl_RA_read_stream.cc
  8. 9
      src/real/input/cl_R_read_stream.cc

4
README

@ -1,8 +1,8 @@
Class Library for Numbers Class Library for Numbers
Copyright (c) Bruno Haible 1988-2008 Copyright (c) Bruno Haible 1988-2008
Copyright (c) Richard Kreckel 2000-2009
Copyright (c) Alexei Sheplyakov 2008
Copyright (c) Richard Kreckel 2000-2012
Copyright (c) Alexei Sheplyakov 2008-2010
GPL GPL

2
doc/cln.texi

@ -36,7 +36,7 @@ Published by Bruno Haible, @code{<haible@@clisp.cons.org>} and
Richard B. Kreckel, @code{<kreckel@@ginac.de>}. Richard B. Kreckel, @code{<kreckel@@ginac.de>}.
Copyright (C) Bruno Haible 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008. Copyright (C) Bruno Haible 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008.
Copyright (C) Richard B. Kreckel 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011.
Copyright (C) Richard B. Kreckel 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012.
Copyright (C) Alexei Sheplyakov 2008, 2010. Copyright (C) Alexei Sheplyakov 2008, 2010.
Permission is granted to make and distribute verbatim copies of Permission is granted to make and distribute verbatim copies of

4
src/base/cl_free.cc

@ -34,8 +34,8 @@ void cl_free_heap_object (cl_heap* pointer)
static const char * copyright_notice[] = { static const char * copyright_notice[] = {
" \n" " \n"
"Copyright (c) Bruno Haible 1988-2008 \n" "Copyright (c) Bruno Haible 1988-2008 \n"
"Copyright (c) Richard Kreckel 2000-2009 \n"
"Copyright (c) Alexei Sheplyakov 2008 \n"
"Copyright (c) Richard Kreckel 2000-2012 \n"
"Copyright (c) Alexei Sheplyakov 2008-2010 \n"
" \n" " \n"
"This program is free software; you can redistribute it and/or modify\n" "This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n" "it under the terms of the GNU General Public License as published by\n"

9
src/complex/input/cl_N_read_stream.cc

@ -91,13 +91,10 @@ const cl_N read_complex (std::istream& stream, const cl_read_flags& flags)
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = stream.get();
if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
stream.putback(c);
c = stream.peek(); // Avoid fail state on EOF.
if (stream.eof() || stream.fail() || !number_char_p(c))
break; break;
}
c = stream.get();
} }
done: done:
// Parse the number. // Parse the number.

9
src/float/input/cl_F_read_stream.cc

@ -82,13 +82,10 @@ const cl_F read_float (std::istream& stream, const cl_read_flags& flags)
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = stream.get();
if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
stream.putback(c);
c = stream.peek(); // Avoid fail state on EOF.
if (stream.eof() || stream.fail() || !number_char_p(c))
break; break;
}
c = stream.get();
} }
// Parse the number. // Parse the number.
return read_float(flags, return read_float(flags,

9
src/integer/input/cl_I_read_stream.cc

@ -82,13 +82,10 @@ const cl_I read_integer (std::istream& stream, const cl_read_flags& flags)
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = stream.get();
if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
stream.putback(c);
c = stream.peek(); // Avoid fail state on EOF.
if (stream.eof() || stream.fail() || !number_char_p(c))
break; break;
}
c = stream.get();
} }
// Parse the number. // Parse the number.
return read_integer(flags, return read_integer(flags,

9
src/rational/input/cl_RA_read_stream.cc

@ -83,13 +83,10 @@ const cl_RA read_rational (std::istream& stream, const cl_read_flags& flags)
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = stream.get();
if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
stream.putback(c);
c = stream.peek(); // Avoid fail state on EOF.
if (stream.eof() || stream.fail() || !number_char_p(c))
break; break;
}
c = stream.get();
} }
// Parse the number. // Parse the number.
return read_rational(flags, return read_rational(flags,

9
src/real/input/cl_R_read_stream.cc

@ -82,13 +82,10 @@ const cl_R read_real (std::istream& stream, const cl_read_flags& flags)
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = stream.get();
if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
stream.putback(c);
c = stream.peek(); // Avoid fail state on EOF.
if (stream.eof() || stream.fail() || !number_char_p(c))
break; break;
}
c = stream.get();
} }
// Parse the number. // Parse the number.
return read_real(flags, return read_real(flags,

Loading…
Cancel
Save