Interesting segmentation fault, I cannot find root cause

B

Ben Bacarisse

b3hzat said:
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.
 
D

Dann Corbit

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);

free (strings);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top