Interesting segmentation fault, I cannot find root cause

Discussion in 'C Programming' started by b3hzat, Jul 20, 2010.

  1. b3hzat

    b3hzat Guest

    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..
    b3hzat, Jul 20, 2010
    #1
    1. Advertising

  2. 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.
    Ben Bacarisse, Jul 20, 2010
    #2
    1. Advertising

  3. b3hzat

    Dann Corbit Guest

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

    free (strings);
    }
    Dann Corbit, Jul 21, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    615
    Mike Wahler
    May 15, 2005
  2. Hon Seng Phuah

    Free memory cause segmentation fault.

    Hon Seng Phuah, Jul 7, 2004, in forum: C Programming
    Replies:
    8
    Views:
    623
    Old Wolf
    Jul 7, 2004
  3. I_have_nothing

    What can cause Segmentation Fault on Linux?

    I_have_nothing, Apr 14, 2005, in forum: C Programming
    Replies:
    3
    Views:
    406
    Jason
    Apr 15, 2005
  4. Sameer
    Replies:
    19
    Views:
    465
  5. Replies:
    2
    Views:
    266
    Richard Heathfield
    May 17, 2007
Loading...

Share This Page