istream segfault

Discussion in 'C++' started by Jim Strathmeyer, Jul 22, 2004.

  1. Under what circumstances would closing a istream object (such as
    'in.close()') SEGFAULT?
    Jim Strathmeyer, Jul 22, 2004
    #1
    1. Advertising

  2. On Thu, 22 Jul 2004 15:04:23 -0400 (EDT), Jim Strathmeyer
    <> wrote:

    >
    > Under what circumstances would closing a istream object (such as
    > 'in.close()') SEGFAULT?


    When you have a bug in your program. What else?

    All the usual suspects, writing past he end of an array, writing through a
    garbage pointer, freeing the same memory twice, etc. etc. All these bugs
    can cause anything to happen.

    Bugs rarely have any logic. You can rarely say 'well the symptom is this,
    therefore the bug must be that', at least that sort of intuition only
    comes with much experience.

    john
    John Harrison, Jul 22, 2004
    #2
    1. Advertising

  3. On Thu, 22 Jul 2004, John Harrison wrote:

    > On Thu, 22 Jul 2004 15:04:23 -0400 (EDT), Jim Strathmeyer
    > <> wrote:
    >
    > > Under what circumstances would closing a istream object (such as
    > > 'in.close()') SEGFAULT?

    >
    > When you have a bug in your program. What else?
    >
    > All the usual suspects, writing past he end of an array, writing through a
    > garbage pointer, freeing the same memory twice, etc. etc. All these bugs
    > can cause anything to happen.
    >
    > Bugs rarely have any logic. You can rarely say 'well the symptom is this,
    > therefore the bug must be that', at least that sort of intuition only
    > comes with much experience.


    ....right... but why would a SEGFAULT happen inside a library function?
    Jim Strathmeyer, Jul 22, 2004
    #3
  4. Jim Strathmeyer

    David Harmon Guest

    On Thu, 22 Jul 2004 15:24:26 -0400 (EDT) in comp.lang.c++, Jim
    Strathmeyer <> wrote,
    >
    >...right... but why would a SEGFAULT happen inside a library function?


    Most typical reason... because the structures used by the library to
    manage the memory free store had been clobbered by any of the kinds of
    activity that John mentioned. When trying to return the released memory
    formerly used by your stream, the library encounters a pointer to outer
    space.
    David Harmon, Jul 22, 2004
    #4
  5. Jim Strathmeyer

    Mike Wahler Guest

    "Jim Strathmeyer" <> wrote in message
    news:p...
    >
    > On Thu, 22 Jul 2004, John Harrison wrote:
    >
    > > On Thu, 22 Jul 2004 15:04:23 -0400 (EDT), Jim Strathmeyer
    > > <> wrote:
    > >
    > > > Under what circumstances would closing a istream object (such as
    > > > 'in.close()') SEGFAULT?

    > >
    > > When you have a bug in your program. What else?
    > >
    > > All the usual suspects, writing past he end of an array, writing through

    a
    > > garbage pointer, freeing the same memory twice, etc. etc. All these bugs
    > > can cause anything to happen.
    > >
    > > Bugs rarely have any logic. You can rarely say 'well the symptom is

    this,
    > > therefore the bug must be that', at least that sort of intuition only
    > > comes with much experience.

    >
    > ...right... but why would a SEGFAULT happen inside a library function?


    If you've done something 'wrong' (such as some of the things
    John mentioned) *anywhere* in your program, it could easily
    cause corruption anywhere else in your program, including inside
    library code. IMO the best way for tracking down a bug whose source
    is unknown and/or not easily reprocible is careful, methodical
    testing, and selective removal of (relatively large) sections of
    code, testing each version. One a large section has been identified
    as the culprit, start removing smaller sections of that section.

    Good debuggers also help much.

    -Mike
    Mike Wahler, Jul 23, 2004
    #5
    1. Advertising

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. Todd Beauchemin

    overloaded >> and istream delimiters

    Todd Beauchemin, Jul 31, 2003, in forum: C++
    Replies:
    1
    Views:
    427
    Victor Bazarov
    Jul 31, 2003
  2. Victor Bazarov

    Re: istream::getline

    Victor Bazarov, Aug 13, 2003, in forum: C++
    Replies:
    0
    Views:
    2,106
    Victor Bazarov
    Aug 13, 2003
  3. Thomas Matthews

    istream in init list

    Thomas Matthews, Sep 19, 2003, in forum: C++
    Replies:
    4
    Views:
    542
    Kevin Goodsell
    Sep 20, 2003
  4. xmllmx
    Replies:
    5
    Views:
    572
    Jorgen Grahn
    Jun 15, 2010
  5. Andrey Vul
    Replies:
    8
    Views:
    667
    Richard Bos
    Jul 30, 2010
Loading...

Share This Page