This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/21286] New: GNU extension stdio_filebuf problems when reading from pipe
- From: "ralfixx at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Apr 2005 15:54:16 -0000
- Subject: [Bug c++/21286] New: GNU extension stdio_filebuf problems when reading from pipe
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Attach stdin (or any other FILE*) to an iostream via the rdbuf() created from a
FILE* by using the GNU extension stdio_filebuf() (see attached C++-File).
Input is just some big file with +11MB:
% wc -c big_file
11601584 big_file
This reads incorrect number of bytes when stdin is a pipe and using an block
size which is not some power of 2. The number of bytes read differs from run to run.
% cat big_file | ./t400 8687
total bytes read 9347072, blocks 1076
% cat big_file | ./t400 8687
total bytes read 978944, blocks 113
% cat big_file | ./t400 8687
total bytes read 8679424, blocks 1000
% cat big_file | ./t400 8687
total bytes read 3424256, blocks 395
% cat big_file | ./t400 8687
total bytes read 11601584, blocks 1336
% cat big_file | ./t400 2048
total bytes read 11601584, blocks 5665
% cat big_file | ./t400 2048
total bytes read 11601584, blocks 5665
No errors when stdin is redirected directly to the file.
% ./t400 8676 < big_file
total bytes read 11601584, blocks 1338
% ./t400 8676 < big_file
total bytes read 11601584, blocks 1338
% ./t400 8676 < big_file
total bytes read 11601584, blocks 1338
% ./t400 8676 < big_file
total bytes read 11601584, blocks 1338
Also no problems when reading in 2048 or 4096 blocks:
% cat big_file | ./t400 2048
total bytes read 11601584, blocks 5665
% cat big_file | ./t400 2048
total bytes read 11601584, blocks 5665
% cat big_file | ./t400 2048
total bytes read 11601584, blocks 5665
% cat big_file | ./t400 4096
total bytes read 11601584, blocks 2833
% cat big_file | ./t400 4096
total bytes read 11601584, blocks 2833
% cat big_file | ./t400 4096
total bytes read 11601584, blocks 2833
Same problem on HP-UX 10.20 with gcc-4.0.0 (and 3.4.3 if it matters).
The same program runs w/o problems in gcc-3.4.1 and gcc-3.3.3 on the same platforms.
I actually had a shell loop trying block sizes from 1 to 10000 to find the
problematic ones, so if 8687 does not reproduce the bug, try the follwoing shell
loop:
i=8000
while test $i -lt 9000 ; do
echo -e "$i: \\c"
cat big_file | ./t400 $i
i=`echo $i+1 | bc`
done
R'
--
Summary: GNU extension stdio_filebuf problems when reading from
pipe
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ralfixx at gmx dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21286