1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
From: Richard Kreckel <kreckel@ginac.de>
Date: Sun, 18 Mar 2012 23:35:03 +0000 (+0100)
Subject: Avoid input stream fail state when reading number at EOF.
X-Git-Url: http://www.ginac.de/CLN/cln.git/?p=cln.git;a=commitdiff_plain;h=4985c8a7895076df62758466c86cd1bc9df10438
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.
---
diff --git a/README b/README
index 7de3f55..d445d55 100644
--- 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
diff --git a/doc/cln.texi b/doc/cln.texi
index 354cacc..d5ed502 100644
--- a/doc/cln.texi
+++ b/doc/cln.texi
@@ -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
diff --git a/src/base/cl_free.cc b/src/base/cl_free.cc
index ccda8af..a829aa2 100644
--- a/src/base/cl_free.cc
+++ b/src/base/cl_free.cc
@@ -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"
diff --git a/src/complex/input/cl_N_read_stream.cc b/src/complex/input/cl_N_read_stream.cc
index 139af04..fc207aa 100644
--- a/src/complex/input/cl_N_read_stream.cc
+++ b/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;
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.
diff --git a/src/float/input/cl_F_read_stream.cc b/src/float/input/cl_F_read_stream.cc
index baafc3b..044e4d6 100644
--- a/src/float/input/cl_F_read_stream.cc
+++ b/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;
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,
diff --git a/src/integer/input/cl_I_read_stream.cc b/src/integer/input/cl_I_read_stream.cc
index 227d845..b242ae7 100644
--- a/src/integer/input/cl_I_read_stream.cc
+++ b/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;
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,
diff --git a/src/rational/input/cl_RA_read_stream.cc b/src/rational/input/cl_RA_read_stream.cc
index bba1d03..9e5f4f6 100644
--- a/src/rational/input/cl_RA_read_stream.cc
+++ b/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;
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,
diff --git a/src/real/input/cl_R_read_stream.cc b/src/real/input/cl_R_read_stream.cc
index 56b01d3..c032eee 100644
--- a/src/real/input/cl_R_read_stream.cc
+++ b/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;
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,
|