Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > string resize problem

Reply
Thread Tools

string resize problem

 
 
Scott
Guest
Posts: n/a
 
      07-25-2003
Hello,

I am running into something I have never seen before and can't
explain. Hopefully someone can help.

So I have a method that attempts to fill a string with a value with an
istringstream.

istringtream iss;
string str_val;

iss >> str_val;


This gets called hundreds of times and works, but every now and then I
get a bus error. When I run it in the debugger, it fails here - well
actually in the code that gets invoked by this. Below is the STL
method that gets called based on this. The line that is causing the
bus error is the "s.resize(0)" line. How is this possible? Why
doesn't it always fail? What would cause this line to fail? I can't
recreate the problem with a simple program. What would cause
resize() to throw an exception?

Any ideas.

template <class charT, class traits, class Allocator>
istream &
operator>> (istream &is, basic_string <charT, traits, Allocator> &s)
{
int w = is.width (0);
if (is.ipfx0 ())
{
register streambuf *sb = is.rdbuf ();
s.resize (0); <--------------------This causes bus
exception
while (1)
{
int ch = sb->sbumpc ();
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      07-25-2003

"Scott" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) om...
> Hello,
>
> I am running into something I have never seen before and can't
> explain. Hopefully someone can help.
>

I'd bet a donut that you are screwing up the memory arena elsewhere, writing off the end
of an array allocation or such. The string just gets the side effect
of that when it goes to allocate some memory.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
STL std::string difference between reserve and resize () Rakesh Kumar C++ 2 12-19-2007 09:06 AM
Interesting string.resize behavior v4vijayakumar C++ 28 06-23-2007 08:58 PM
Re: Interesting string.resize behavior Default User C Programming 4 06-23-2007 08:36 PM
problem with string::resize metaosp C++ 23 02-14-2006 12:40 AM
How to resize all images sizes and coordinates of the images on resize browser rams.kakara@gmail.com ASP General 2 02-13-2005 09:03 AM



Advertisments