]> www.ginac.de Git - cln.git/commitdiff
Avoid input stream fail state when reading number at EOF.
authorRichard Kreckel <kreckel@ginac.de>
Sun, 18 Mar 2012 23:35:03 +0000 (00:35 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Sun, 18 Mar 2012 23:46:05 +0000 (00:46 +0100)
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.

README
doc/cln.texi
src/base/cl_free.cc
src/complex/input/cl_N_read_stream.cc
src/float/input/cl_F_read_stream.cc
src/integer/input/cl_I_read_stream.cc
src/rational/input/cl_RA_read_stream.cc
src/real/input/cl_R_read_stream.cc

diff --git a/README b/README
index 7de3f55379d24497b95552580407fb8f5d986af0..d445d55e1d5387bb452e76d92adf62fb0d79cffa 100644 (file)
--- a/README
+++ b/README
@@ -1,8 +1,8 @@
 Class Library for Numbers
 
 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
 
index 354cacce1c21e1889b36a90513f842d9f803c349..d5ed502081db7f11a018f1f150d6266aeebd455b 100644 (file)
@@ -36,7 +36,7 @@ Published by Bruno Haible, @code{<haible@@clisp.cons.org>} and
 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)  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.
 
 Permission is granted to make and distribute verbatim copies of
index ccda8afa9ca8a0a3319cb503c6e6d3812dea7bba..a829aa24ac08a854dd4936b3a6ef47fc2bd10eab 100644 (file)
@@ -34,8 +34,8 @@ void cl_free_heap_object (cl_heap* pointer)
 static const char * copyright_notice[] = {
   "                                                                    \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"
   "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"
index 139af04d20d2d841c380282aacbd9a9a5182a07e..fc207aa842075090ec7e428dc54b60dca0eeffbe 100644 (file)
@@ -91,13 +91,10 @@ const cl_N read_complex (std::istream& stream, const cl_read_flags& flags)
                goto syntax1;
        loop {
                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;
-               }
+               c = stream.get();
        }
 done:
        // Parse the number.
index baafc3bb24a961c240fcbd110629944676512742..044e4d663c03bd904bdb9ec8066e266f2618ab27 100644 (file)
@@ -82,13 +82,10 @@ const cl_F read_float (std::istream& stream, const cl_read_flags& flags)
                goto syntax1;
        loop {
                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;
-               }
+               c = stream.get();
        }
        // Parse the number.
        return read_float(flags,
index 227d845be9e70ff3961079fee504fc67fc033be6..b242ae7210a450221edcb11323b932fcba121b61 100644 (file)
@@ -82,13 +82,10 @@ const cl_I read_integer (std::istream& stream, const cl_read_flags& flags)
                goto syntax1;
        loop {
                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;
-               }
+               c = stream.get();
        }
        // Parse the number.
        return read_integer(flags,
index bba1d030828743bcc635c6b2b1b6e985f77008bc..9e5f4f65e16f40fdc249305a509efe7ff926ba74 100644 (file)
@@ -83,13 +83,10 @@ const cl_RA read_rational (std::istream& stream, const cl_read_flags& flags)
                goto syntax1;
        loop {
                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;
-               }
+               c = stream.get();
        }
        // Parse the number.
        return read_rational(flags,
index 56b01d32381e2ec744af2582ea268362cc2ef993..c032eee909f50233c068da72580796c3ce350512 100644 (file)
@@ -82,13 +82,10 @@ const cl_R read_real (std::istream& stream, const cl_read_flags& flags)
                goto syntax1;
        loop {
                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;
-               }
+               c = stream.get();
        }
        // Parse the number.
        return read_real(flags,