473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

istream segfault


Under what circumstances would closing a istream object (such as
'in.close()') SEGFAULT?
Jul 22 '05 #1
4 1860
On Thu, 22 Jul 2004 15:04:23 -0400 (EDT), Jim Strathmeyer
<no************@andrew.cmu.edu> 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
Jul 22 '05 #2

On Thu, 22 Jul 2004, John Harrison wrote:
On Thu, 22 Jul 2004 15:04:23 -0400 (EDT), Jim Strathmeyer
<no************@andrew.cmu.edu> 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?
Jul 22 '05 #3
On Thu, 22 Jul 2004 15:24:26 -0400 (EDT) in comp.lang.c++, Jim
Strathmeyer <no************@andrew.cmu.edu> 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.

Jul 22 '05 #4

"Jim Strathmeyer" <no************@andrew.cmu.edu> wrote in message
news:Pi**********************************@unix43.a ndrew.cmu.edu...

On Thu, 22 Jul 2004, John Harrison wrote:
On Thu, 22 Jul 2004 15:04:23 -0400 (EDT), Jim Strathmeyer
<no************@andrew.cmu.edu> 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

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Thomas Matthews | last post by:
Hi, In some threads, some people mentioned that variable initialization is best performed in an initialization list. Is there a way to initialize a variable from an istream in an...
3
by: matthurne | last post by:
I'm doing a chapter 12 exercise from Accelerated C++ ... writing a string-like class which stores its data in a low-level way. My class, called Str, uses a char array and length variable. I've...
13
by: Randy | last post by:
Is there any way to do this? I've tried tellg() followed by seekg(), inserting the stream buffer to an ostringstream (ala os << is.rdbuf()), read(), and having no luck. The problem is, all of...
13
by: Gianni Mariani | last post by:
What I would like to do is read bytes from a stream, any number and any time. I would like it to wait until there are any bytes to read. I want the exact same functionality as cstdio's "fread"...
3
by: KWienhold | last post by:
I'm currently writing an application (using Visual Studio 2003 SP1 and C#) that stores files and additional information in a single compound file using IStorage/IStream. Since files in a compound...
2
by: Colonel | last post by:
It seems that the problems have something to do with the overloading of istream operator ">>", but I just can't find the exact problem. // the declaration friend std::istream &...
3
by: Kourosh | last post by:
Hi all, I'm trying to call a COM function from C# The function gets a paramter of type IStream in C++. I've found the type System.Runtime.InteropServices.ComTypes.IStream, however I'm not sure...
4
by: Ralf | last post by:
Hallo, I'm trying to call a COM function from C#. The function has a parameter from the type array of IStream* (IStream**). The COM component (out-proc-server (.exe)) has the following code: ...
0
by: admb600 | last post by:
I wouldn't normally beg but my dissertation is due in, in a couple of weeks and I am in way over my head here.. Fixing this issue will make or break the project and my degree.. The goal is to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.