This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [v3] Absolutely avoid integer overflow in istream::ignore


Paolo Carlini wrote:

also in the light of the ongoing discussion about aggressive loop
unrolling, I decided to remove an hack of mine which relied on an
infinite loop and integer overflow in order to deal correctly with
huge ignore (> 2G) on LFS-enbled 32-bit machines.

Also committed the below small follow up, to match more closely user expectations in this corner case (also fixed a stupi typo, humpf!)

Tested x86-linux.

Paolo.

///////////////
2005-01-03  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/istream.tcc (ignore(streamsize), ignore(streamsize,
	int_type)): Reset _M_gcount to numeric_limits<streamsize>::min().
	* src/istream.cc (basic_istream<char>::ignore(streamsize, int_type),
	basic_istream<wchar_t>::ignore(streamsize, int_type)): Likewise.
	* src/istream.cc (basic_istream<char>::ignore(streamsize),
	basic_istream<wchar_t>::ignore(streamsize)): Likewise; fix a typo.
diff -urN libstdc++-v3-orig/include/bits/istream.tcc libstdc++-v3/include/bits/istream.tcc
--- libstdc++-v3-orig/include/bits/istream.tcc	2005-01-03 00:19:08.000000000 +0100
+++ libstdc++-v3/include/bits/istream.tcc	2005-01-03 14:45:33.000000000 +0100
@@ -695,7 +695,7 @@
 		    }
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof))
-		    _M_gcount = 0;
+		    _M_gcount = numeric_limits<streamsize>::min();
 		  else
 		    break;
 		}
@@ -742,7 +742,7 @@
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof)
 		      && !traits_type::eq_int_type(__c, __delim))
-		    _M_gcount = 0;
+		    _M_gcount = numeric_limits<streamsize>::min();
 		  else
 		    break;
 		}
diff -urN libstdc++-v3-orig/src/istream.cc libstdc++-v3/src/istream.cc
--- libstdc++-v3-orig/src/istream.cc	2005-01-03 00:38:32.000000000 +0100
+++ libstdc++-v3/src/istream.cc	2005-01-03 14:46:55.000000000 +0100
@@ -146,7 +146,7 @@
 		    }
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof))
-		    _M_gcount == 0;
+		    _M_gcount = numeric_limits<streamsize>::min();
 		  else
 		    break;
 		}
@@ -211,7 +211,7 @@
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof)
 		      && !traits_type::eq_int_type(__c, __delim))
-		    _M_gcount = 0;
+		    _M_gcount = numeric_limits<streamsize>::min();
 		  else
 		    break;
 		}
@@ -424,7 +424,7 @@
 		    }
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof))
-		    _M_gcount == 0;
+		    _M_gcount = numeric_limits<streamsize>::min();
 		  else
 		    break;
 		}
@@ -489,7 +489,7 @@
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof)
 		      && !traits_type::eq_int_type(__c, __delim))
-		    _M_gcount = 0;
+		    _M_gcount = numeric_limits<streamsize>::min();
 		  else
 		    break;
 		}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]