This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3, 3.4] Fix libstdc++/21286
- From: Paolo Carlini <pcarlini at suse dot de>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Cc: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Date: Mon, 18 Jul 2005 18:42:08 +0200
- Subject: [v3, 3.4] Fix libstdc++/21286
Hi everyone, hi Gaby,
Ralf Fassel solicitate an action in 3_4-branch too, because this bug is
actually a regression from 3.4.2. Personally, I consider the fix safe,
because this code is generally stable and we had the fix in mainline and
4_0-branch for some time.
Ok?
Thanks,
Paolo.
////////////
2005-07-18 Paolo Carlini <pcarlini@suse.de>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/21286
* include/bits/fstream.tcc (basic_filebuf<>::xsgetn):
Loop on short reads.
Index: fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.116.4.8
diff -u -r1.116.4.8 fstream.tcc
--- fstream.tcc 8 Nov 2004 00:41:15 -0000 1.116.4.8
+++ fstream.tcc 18 Jul 2005 15:43:45 -0000
@@ -535,13 +535,28 @@
__n -= __avail;
}
- const streamsize __len = _M_file.xsgetn(reinterpret_cast<char*>(__s),
- __n);
- if (__len == -1)
- __throw_ios_failure(__N("basic_filebuf::xsgetn "
- "error reading the file"));
- __ret += __len;
- if (__len == __n)
+ // Need to loop in case of short reads (relatively common
+ // with pipes).
+ streamsize __len;
+ for (;;)
+ {
+ __len = _M_file.xsgetn(reinterpret_cast<char*>(__s),
+ __n);
+ if (__len == -1)
+ __throw_ios_failure(__N("basic_filebuf::xsgetn "
+ "error reading the file"));
+ if (__len == 0)
+ break;
+
+ __n -= __len;
+ __ret += __len;
+ if (__n == 0)
+ break;
+
+ __s += __len;
+ }
+
+ if (__n == 0)
{
_M_set_buffer(0);
_M_reading = true;