istream segfault

J

Jim Strathmeyer

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

John Harrison

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
 
J

Jim Strathmeyer

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?
 
D

David Harmon

On Thu, 22 Jul 2004 15:24:26 -0400 (EDT) in comp.lang.c++, Jim
Strathmeyer said:
...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.
 
M

Mike Wahler

Jim Strathmeyer said:
...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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top