Hello all,
I have a class member, which calls another member from the same class. The
problem I'm experiencing is that the nested function executes fine, but
causes a segmentation fault as it exits. I've traced it to the point in the
code just before the line following the nested function is to be called, or
conversely right after the last line of the nested function.
What might be my problem? I'm hoping someone can give me some guidance on
what sort of things to check. I can't even think where to start.
d 14 11688
deancoo wrote: I have a class member, which calls another member from the same class. The problem I'm experiencing is that the nested function executes fine, but causes a segmentation fault as it exits. I've traced it to the point in the code just before the line following the nested function is to be called, or conversely right after the last line of the nested function.
What might be my problem? I'm hoping someone can give me some guidance on what sort of things to check. I can't even think where to start.
Sounds like a garden variety memory overrun problem. You stomp over your
own call stack, most likely. Check writing beyond the bounds of an array.
V
deancoo schrieb: Hello all,
I have a class member, which calls another member from the same class. The problem I'm experiencing is that the nested function executes fine, but causes a segmentation fault as it exits. I've traced it to the point in the code just before the line following the nested function is to be called, or conversely right after the last line of the nested function.
What might be my problem? I'm hoping someone can give me some guidance on what sort of things to check. I can't even think where to start.
you've corrupted your stack somehow.
look for overflows in arrays on the stack and the like.
"deancoo" <s2*******@yaho o.ca> wrote in message
news:UhB2e.1347 78$gJ3.30063@cl grps13... Hello all,
I have a class member, which calls another member from the same class. The problem I'm experiencing is that the nested function executes fine, but causes a segmentation fault as it exits. I've traced it to the point in the code just before the line following the nested function is to be called, or conversely right after the last line of the nested function.
What might be my problem? I'm hoping someone can give me some guidance on what sort of things to check. I can't even think where to start.
d
Found the problem, the function was previously defined to return something,
later I changed that to void by removing the 'return' statement only (dumb
me). Anyway, that's what happens when a function that's defined to return
something doesn't.
Thanks for your comments,
d
"deancoo" <s2*******@yaho o.ca> wrote in message
news:SyB2e.1347 83$gJ3.116805@c lgrps13... "deancoo" <s2*******@yaho o.ca> wrote in message news:UhB2e.1347 78$gJ3.30063@cl grps13... Hello all,
I have a class member, which calls another member from the same class. The problem I'm experiencing is that the nested function executes fine, but causes a segmentation fault as it exits. I've traced it to the point in the code just before the line following the nested function is to be called, or conversely right after the last line of the nested function.
What might be my problem? I'm hoping someone can give me some guidance on what sort of things to check. I can't even think where to start.
d
Found the problem, the function was previously defined to return something, later I changed that to void by removing the 'return' statement only (dumb me). Anyway, that's what happens when a function that's defined to return something doesn't.
Thanks for your comments, d
You removed the return statement, but the function still specified a return
type? That shouldn't even compile! I'd get a new compiler if it does.
-Howard
"deancoo" <s2*******@yaho o.ca> wrote in
news:UhB2e.1347 78$gJ3.30063@cl grps13: Hello all,
I have a class member, which calls another member from the same class. The problem I'm experiencing is that the nested function executes fine, but causes a segmentation fault as it exits. I've traced it to the point in the code just before the line following the nested function is to be called, or conversely right after the last line of the nested function.
What might be my problem? I'm hoping someone can give me some guidance on what sort of things to check. I can't even think where to start.
[Note: platform specific answer, but hopefully generic enough....]
A couple of possibilities:
1) You've probably overrun one of your local variables, causing some
portion of your call stack to be stomped on. When your function attempts
to return to the calling site, the return address is scrambled. Check all
accesses to your local variables via a pointer. Also check if you have any
arrays as local variables and ensure that you haven't accessed beyond the
bounds of your array. That sort of thing.
2) A destructor of a local variable is going bad, and causing a segfault.
3) Something during the construction of the return value of your function
may be causing a segfault.
deancoo wrote: [...] Found the problem, the function was previously defined to return something, later I changed that to void by removing the 'return' statement only (dumb me). Anyway, that's what happens when a function that's defined to return something doesn't.
It's called "undefined behaviour", and you got a very good example of it.
Unfortunately, you can't easily say that when the function returns with
a bang, it's because it falls off its end when defined to return some
object. FWIW, you could get nothing special -- it's allowed just like
anything else.
V
Howard wrote: [...] You removed the return statement, but the function still specified a return type? That shouldn't even compile! I'd get a new compiler if it does.
Why shouldn't it compile? Which part of the Standard says that a program
that has such function is ill-formed? While you're looking for it, check
out 6.6.3/2, the last sentence.
V
"Howard" <al*****@hotmai l.com> wrote in message
news:1C******** **********@bgtn sc04-news.ops.worldn et.att.net... "deancoo" <s2*******@yaho o.ca> wrote in message news:SyB2e.1347 83$gJ3.116805@c lgrps13... "deancoo" <s2*******@yaho o.ca> wrote in message news:UhB2e.1347 78$gJ3.30063@cl grps13... Hello all,
I have a class member, which calls another member from the same class. The problem I'm experiencing is that the nested function executes fine, but causes a segmentation fault as it exits. I've traced it to the point in the code just before the line following the nested function is to be called, or conversely right after the last line of the nested function.
What might be my problem? I'm hoping someone can give me some guidance on what sort of things to check. I can't even think where to start.
d
Found the problem, the function was previously defined to return something, later I changed that to void by removing the 'return' statement only (dumb me). Anyway, that's what happens when a function that's defined to return something doesn't.
Thanks for your comments, d
You removed the return statement, but the function still specified a return type? That shouldn't even compile! I'd get a new compiler if it does.
-Howard
gcc 3.4.3
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:CF******** **********@news read1.mlpsca01. us.to.verio.net ... Howard wrote: [...] You removed the return statement, but the function still specified a return type? That shouldn't even compile! I'd get a new compiler if it does.
Why shouldn't it compile? Which part of the Standard says that a program that has such function is ill-formed? While you're looking for it, check out 6.6.3/2, the last sentence.
V
I don't have a copy of the Standard, but Stroustrup's book "The C++
Programming Language", in section 7.3, states: "A value must be returned
from a function that is not declared void". Obviously, stating that
something is required doesn't neccessarily mean that the standard dictates
that a program that does not meet such a requirement is ill-formed, but
surely in this case it is...? My compiler(s) certainly won't let it
compile, and I can't see any reason why any compiler _would_ allow it.
-Howard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sivignon |
last post by:
Hi,
I'm writing a php script which deals with 3 ORACLE databases.
This script is launch by a script shell on an linux machine like this :
/../php/bin/php ./MySript.php (PHP 4.3.3)
My script works fine and do all what I need.
But at the end of the execution, I can read "Segmentation Fault".
The segmentation fault appear at the end of my script execution,
|
by: Peter Dragun |
last post by:
I am generally new to programming under Unix, but know how to code under
Windows. I have to create a simple program, that takes the following
information from a file using redirection:
4 4 4 4 4 4 5 5 5 5 5 5 3 3 3 3 3 3 3 3 2 2 2 10 10 10 1 1
3 3 3 3 3 3 3 3 3 2 2 2 12 12 12 1 7 7 7 7 4
12 13 13 5 5 5 3 3 9 7 7 7 5 4 4 4 3 3 3 3
read each line, and "compress the information" to the following out print to
be printed on screen:
|
by: Fra-it |
last post by:
Hi everybody,
I'm trying to make the following code running properly, but I can't get
rid of the "SEGMENTATION FAULT" error message when executing.
Reading some messages posted earlier, I understood that a segmentation
fault can occur whenever I declare a pointer and I leave it
un-initialized.
So I thought the problem here is with the (const char *)s in the stuct
flightData (please note that I get the same fault declaring as char *
the...
|
by: Paminu |
last post by:
I have a wierd problem.
In my main function I print "test" as the first thing. But if I run the call
to node_alloc AFTER the printf call I get a segmentation fault and test is
not printed!
#include <stdlib.h>
#include <stdio.h>
typedef struct _node_t {
|
by: pycraze |
last post by:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.
If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in...
| |
by: SP |
last post by:
The following code compiles with no errors, but fails with
"Segmentation Fault" when I run it .
I tracked the problem down to the code which populates the
image.pixel_p array and I assume that the real problem is with the
memory allocation.
The values for the rows and columns are correct and I print them to
make sure.
I added a print statement to the code that is crashing and it gets
about 90% through the array before it fails.
|
by: DanielJohnson |
last post by:
int main()
{
printf("\n Hello World");
main;
return 0;
}
This program terminate just after one loop while the second program
goes on infinitely untill segmentation fault (core dumped) on gcc. The
only difference is that in first I only call "main" and in second call
|
by: Goran |
last post by:
Hi all,
i have a problem on program termination.
At the moment when main() ends my program creates a segmentation
fault.
#include <libmylib/myObject.h>
|
by: Rares Vernica |
last post by:
Hello,
I have a strange problem.
I compile my code with g++ (GCC) 4.1.2. My code runs just fine if I use
the -O2 optimization flag. valgrind does not report any memory leak.
When I use the -O3 flag, everything falls apart. The program reports
Segmentation fault. valgrind reports some Invalid read.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |