Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Interesting segmentation fault, I cannot find root cause

Reply
Thread Tools

Interesting segmentation fault, I cannot find root cause

 
 
b3hzat
Guest
Posts: n/a
 
      07-20-2010
Hi everyone,

I have a interesting segmentation fault in this code

http://pastebin.com/rP86ZLcr

I cannot find root cause, so any idea would be more than welcome.

Thanks..
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      07-20-2010
b3hzat <> writes:

> I have a interesting segmentation fault in this code
>
> http://pastebin.com/rP86ZLcr


It's only 43 lines (13 of which are blank) -- that's not too long to post
here. However, it's only one function. Are you sure the error is there
not elsewhere?

> I cannot find root cause, so any idea would be more than welcome.


Nothing jumps out. I presume you've checked that backtrace_symbols could
malloc its storage and that the main text buffer does not overflow?

The function looks odd, of course, because it does nothing! A buffer of
text is constructed but you don't do anything with it.

--
Ben.
 
Reply With Quote
 
 
 
 
Dann Corbit
Guest
Posts: n/a
 
      07-21-2010
In article <2d55060e-95bc-4e38-b5bf-be8dd7583d99
@r27g2000yqb.googlegroups.com>, says...
>
> Hi everyone,
>
> I have a interesting segmentation fault in this code
>
> http://pastebin.com/rP86ZLcr
>
> I cannot find root cause, so any idea would be more than welcome.


You never use swerrBuff, so all that formatting and sprintf() effort
just goes off into the ether-bits.

You do not check to be sure that swerrBuff is long enough until *after*
you have written to it. You should check before.

You forgot to call backtrace() to fill your void pointer list with
symbols.

Here is a sample of how to use it:

#include <stdlib.h>
#include <stdio.h>
/* System specific header, may not work on your system: */
#include <execinfo.h>

void print_trace (void)
{
void *array[10];
int size;
char **strings;
int i;

size = backtrace (array, 10);
strings = backtrace_symbols (array, size);

printf ("Obtained %i stack frames.\n", size);

for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);

free (strings);
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const string which cause segmentation fault - any way to detect this bug during compile time? yccheok@gmail.com C++ 1 05-15-2005 03:54 PM
OutOfMemoryError - how to find root cause kaeli Java 13 04-29-2005 07:50 PM
Re: fclose cause segmentation error CBFalconer C Programming 2 02-17-2005 02:55 PM
will all these messages cause a problem . I am a new subscriber and my computer is downloading 100,000 messages. Will this cause any kind of a problem with my ability to store other items?? Camille White Camille White Computer Support 9 11-08-2004 01:13 AM
Free memory cause segmentation fault. Hon Seng Phuah C Programming 8 07-07-2004 08:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57