help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange SegFaults


From: Donald Tournier
Subject: Strange SegFaults
Date: Wed, 21 Feb 2001 16:31:06 +0000 (GMT)

Hi!

I'm sorry to ask such a vague question, but I can't include all my code
here. Basically, I am having problems with segmentation faults occurring
in strange places. This has happened for several of my programs now. The
strange thing about them happens when I try to debug the code (I guess I
should start using gdb...).

I do this by placing the following line:

cerr << "Line " << __LINE__ << " from file " << __FILE__ << "\n";

at various points in the program, and seeing how far I get. This often
resolves the problem itself: I put these statements at the appropriate
place, and the program runs perfectly. If I take one of them away, it
segfaults again. I really don't know what's happening here. I have
resorted to putting the line 'cerr.flush();' at various 'critical' points
in my code, which is not ideal.

Recently, I have been writing a program using libpng.so to write images,
and I found out (by placing the cerr statements) that the statement:

        buf = new png_byte [width*height];

was causing the segfault. After a lot of playing about, this was solved in
two ways: 
        placing these lines a lot earlier in the code:
                buf = new png_byte;
                delete [] buf;

        or by #include <new>, and using new(nothrow) instead of new.

Could you please give me some pointers as to what I am doing wrong?
Thanks 

donald.

__________________________________________________________________________
Jacques-Donald Tournier                           Physics & Radiology Unit
                                                 Institute of Child Health
email: dtournie@ich.ucl.ac.uk                          30 Guildford Street
tel: +44 (0)20 7405 9200 ext 0338                          London WC1N 1EH




reply via email to

[Prev in Thread] Current Thread [Next in Thread]