c++/2440: istringstream problems after eof encountered

ian.wakeling@knightfisk.com ian.wakeling@knightfisk.com
Fri Mar 30 15:56:00 GMT 2001


>Number:         2440
>Category:       c++
>Synopsis:       istringstream problems after eof encountered
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 30 15:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     ian.wakeling@knightfisk.com
>Release:        2.95.2
>Organization:
>Environment:
Debian 2.2 on an x86

gcc -v:
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.2/specs
gcc version 2.95.2 20000220 (Debian GNU/Linux)                                  
>Description:
Running the following simple program linked to Electric Fence produces the following output:
 
  Electric Fence 2.0.5 Copyright (C) 1987-1998 Bruce Perens.
read A into 0
read B into 1
read C into 2
read D into 3
eof reached
putting back D from 3
putting back C from 2
putting back B from 1
putting back A from 0
 
ElectricFence Aborting: free(bffff928): address not from malloc().
Illegal instruction                                                             
>How-To-Repeat:
source code:

#include <iostream>
#include <sstream>

int main()
{
	std::string			fred = "ABCD";
	std::istringstream	is( fred );
	char				buffer[6];

	size_t	readCount = 0;
	while
	(
		readCount < 6
	&&	is.get( buffer[ readCount ] )
	)
	{
		std::cout << "read " << buffer[ readCount ] << " into " << readCount << std::endl;
		readCount++;
	}

	if( is.eof() )
	{
		std::cout << "eof reached" << std::endl;
		is.clear();
	}

	while( readCount-- > 0 )
	{
		std::cout << "putting back " << buffer[ readCount ] << " from " << readCount << std::endl;
		is.putback( buffer[ readCount ] );
	}

	return 0;
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list