string resize problem

Discussion in 'C++' started by Scott, Jul 25, 2003.

  1. Scott

    Scott Guest

    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 ();
     
    Scott, Jul 25, 2003
    #1
    1. Advertisements

  2. Scott

    Ron Natalie Guest

    "Scott" <> wrote in message news:...
    > 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.
     
    Ron Natalie, Jul 25, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rod Billett

    Phantom space and resize problem.

    Rod Billett, Oct 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    564
    Rod Billett
    Oct 24, 2003
  2. alan

    Resize Image(JPG) Problem

    alan, Sep 1, 2003, in forum: Java
    Replies:
    4
    Views:
    47,147
    Ossie J H Moore
    Sep 1, 2003
  3. metaosp

    problem with string::resize

    metaosp, Feb 12, 2006, in forum: C++
    Replies:
    23
    Views:
    1,162
    Daniel T.
    Feb 14, 2006
  4. v4vijayakumar

    Interesting string.resize behavior

    v4vijayakumar, Jun 21, 2007, in forum: C++
    Replies:
    28
    Views:
    1,048
    James Kanze
    Jun 23, 2007
  5. Default User

    Re: Interesting string.resize behavior

    Default User, Jun 22, 2007, in forum: C Programming
    Replies:
    4
    Views:
    405
    James Kanze
    Jun 23, 2007
  6. Rakesh Kumar
    Replies:
    2
    Views:
    952
    Ioannis Gyftos
    Dec 19, 2007
  7. jenny_luarez
    Replies:
    0
    Views:
    539
    jenny_luarez
    Aug 4, 2009
  8. Replies:
    2
    Views:
    1,489
    Adrienne
    Feb 13, 2005
Loading...