473,324 Members | 1,678 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,324 software developers and data experts.

Segmentation problem after main()

Soujiro
35
here it goes..
Language: C++
OS: Linux RedHat
Compile: g++
What can you suggest happened when a segmentation fault occured right before the program finished execution.

Expand|Select|Wrap|Line Numbers
  1. 17  int main()
  2. 18  {
  3. 19      C_FileHandler cfh;     // a class for file handling
  4. 20      S_ConfigSettings_t my_s; // this is a struct for holding values
  5. 21      int resultCode = cfh.ReadConfigFile( "fileName" , &my_s );
  6. 22      cout << resultCode << endl;
  7. 23      return resultCode;
  8. 24  }
  9.  
so thats it.
output was
Expand|Select|Wrap|Line Numbers
  1. root$ ./main
  2. 1
  3. Segmentation Fault
  4.  
I tried using gdb

Expand|Select|Wrap|Line Numbers
  1. Breakpoint 1, main () at main.C:24
  2. 24      }
  3. (gdb) n
  4. 0x6c2f7377 in ?? ()
  5. (gdb) n
  6. Cannot find bounds of current function
  7.  
24 the last line of the main '}'
when i pressed next line there it goes.. and then "Cannot find bounds of current function".

how can this be.. i tried searching for stupid pointers in the function but cant find any problem.

Can i do somthing about this
Jan 10 '07 #1
2 1460
Soujiro
35
I've solved it already the problem is with the struct.. i have a char* member which was not initialized..

anyway if some problem like this arise from somebody's program.. this may help them..

you can do two things

initialize the char* as char_member[LENGTH] in the definition of the struct.. or

allocate a memory for char* after the allocation of the struct.
Jan 10 '07 #2
Banfa
9,065 Expert Mod 8TB
Or give the struct a constructor that allocates memory to it's pointers and a destructor to free it again.

Segmentation faults as you leave main almost always indicate a stack curruption of some sort such as writing past the end of an array or writing to an uninitialised pointer.
Jan 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Koen | last post by:
Hi, I am trying to track a segmentation fault (EXC_BAD_ACCESS) that's happening in a program I use on Mac OS X (not my own code). The reason for the fault is that the default stack on Mac OS X...
27
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! ...
1
by: Maria | last post by:
Hi, I have read about paging, segmentation and paged segmentation and I believe I have (nearly) understood how these techniques are implemented in hardware. However, I am till confused about the...
6
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...
8
by: Andrea | last post by:
I wrote this code: void * xmalloc (size_t size){ register void *value = OPENSSL_malloc(size); if (value == 0) printf("virtual memory exhausted"); return value; } int _chooseTSK(char*...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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...
1
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.