Sponsored Content
Top Forums Programming C++ Segmentation Fault on exit of main Post 302192253 by jim mcnamara on Tuesday 6th of May 2008 12:40:52 PM
Old 05-06-2008
The stack in main() has been corrupted with an overrun of one or more the variable(s) on it. Probably in one of the functions. It has overwritten the stack pointer that return uses to go back to the calling routines (_start is the usual name).

When main() attempts a return the SP is not "aimed" where it should be. And your code tries to read program text outside of process memory. Address: 0x08

exit() does not return from main or wherever - it starts image rundown directly. It does not use the SP.
You need to fix the problem before you push your code to production. Try running electric fence or whatever other memory checkers you have.

Last edited by jim mcnamara; 05-06-2008 at 01:50 PM..
 

8 More Discussions You Might Find Interesting

1. AIX

Segmentation fault

I am tring to install Lotus Domino/Notes 5.0.5 on a AIX 4.3.3 server. I go to run the cdrom/ibmpow/install and I get the following error. Lotus Notes for Unix Install Program --------------------------------------------- ./install: 10088 Segmentation fault This had Lotus Notes installed... (1 Reply)
Discussion started by: jshaulis
1 Replies

2. Programming

segmentation fault

Hi, I am having this segmentation fault not in the following program, bt. in my lab program . My lab program is horrible long so cannot post it here bt. I am using the following logic in my program which is giving the segmentation fault. Bt. if I run this sample program as it is it dosen't give... (3 Replies)
Discussion started by: mind@work
3 Replies

3. Programming

segmentation fault

What is segmentation fault(core dumped) (1 Reply)
Discussion started by: gokult
1 Replies

4. Programming

Segmentation fault.

I'm getting a segmentation fault. I'm new to Linux programming. Thanks so much for all of your input.:eek: #include </usr/include/mysql++/mysql++.h> #include <stdio.h> #include <iostream> #include <sstream> #include <string.h> using namespace std; int outputToImport(const char*... (1 Reply)
Discussion started by: sepoto
1 Replies

5. Programming

segmentation fault.

This code is causing a segmentation fault and I can't figure out why. I'm new to UNIX and I need to learn how to avoid this segmentation fault thing. Thank you so much. Thanks also for the great answers to my last post.:):b: int main() { mysqlpp::Connection conn(false); if... (3 Replies)
Discussion started by: sepoto
3 Replies

6. Programming

Segmentation fault in C

i have this code int already_there(char *client_names, char *username) { int i; for(i = 0; i<NUM; i++) { printf("HERE\n"); if (strcmp(client_names, username)==0) return(1); } return(0); } and i get a segmentation fault, whats wrong here? (7 Replies)
Discussion started by: omega666
7 Replies

7. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

8. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
walkcontext(3C) 					   Standard C Library Functions 					   walkcontext(3C)

NAME
walkcontext, printstack - walk stack pointed to by ucontext SYNOPSIS
#include <ucontext.h> int walkcontext(const ucontext_t *uptr, int (*operate_func)(uintptr_t, int, void *), void *usrarg); int printstack(int fd); DESCRIPTION
The walkcontext() function walks the call stack pointed to by uptr, which can be obtained by a call to getcontext(2) or from a signal han- dler installed with the SA_SIGINFO flag. The walkcontext() function calls the user-supplied function operate_func for each routine found on the call stack and each signal handler invoked. The user function is passed three arguments: the PC at which the call or signal occured, the signal number that occured at this PC (0 if no signal occured), and the third argument passed to walkcontext(). If the user function returns a non-zero value, walkcontext() returns without completing the callstack walk. The printstack() function uses walkcontext() to print a symbolic stack trace to the specified file descriptor. This is useful for reporting errors from signal handlers. The printstack() function uses dladdr1() (see dladdr(3C)) to obtain symbolic symbol names. As a result, only global symbols are reported as symbol names by printstack(). RETURN VALUES
Upon successful completion, walkcontext() and printstack() return 0. If walkcontext() cannot read the stack or the stack trace appears corrupted, both functions return -1. ERRORS
No error values are defined. USAGE
The walkcontext() function is typically used to obtain information about the call stack for error reporting, performance analysis, or diag- nostic purposes. Many library functions are not Async-Signal-Safe and should not be used from a signal handler. If walkcontext() is to be called from a signal handler, careful programming is required. In particular, stdio(3C) and malloc(3C) cannot be used. The printstack() function is Async-Signal-Safe and can be called from a signal handler. The output format from printstack() is unstable, as it varies with the scope of the routines. Tail-call optimizations on SPARC eliminate stack frames that would otherwise be present. For example, if the code is of the form #include <stdio.h> main() { bar(); exit(0); } bar() { int a; a = foo(fileno(stdout)); return (a); } foo(int file) { printstack(file); } compiling without optimization will yield a stack trace of the form /tmp/q:foo+0x8 /tmp/q:bar+0x14 /tmp/q:main+0x4 /tmp/q:_start+0xb8 whereas with higher levels of optimization the output is /tmp/q:main+0x10 /tmp/q:_start+0xb8 since both the call to foo() in main and the call to bar() in foo() are handled as tail calls that perform a return or restore in the delay slot. For further information, see The SPARC Architecture Manual. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe | +-----------------------------+-----------------------------+ SEE ALSO
intro(2), getcontext(2), sigaction(2), dladdr(3C), siginfo.h(3HEAD), attributes(5) Weaver, David L. and Tom Germond, eds. The SPARC Architecture Manual, Version 9. Santa Clara: Prentice Hall, 2000. SunOS 5.10 1 Mar 2004 walkcontext(3C)
All times are GMT -4. The time now is 02:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy