tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

swscanf() causing Memory Fault



Hello all.

I imagine this is the right list where I can send questions like that...
here we go:

Today, I compiled STFL (http://www.clifford.at/stfl/) by hand (it is not
available in pkgsrc yet). It has a example program. When trying to run
it, I got a Memory Fault. I got the following backtrace:

    (gdb) bt
    #0  0xbbb0b1cb in __fgetwc_unlock () from /usr/lib/libc.so.12
    #1  0xbbb05fb1 in __vfwscanf_unlocked () from /usr/lib/libc.so.12
    #2  0xbbb05c10 in vswscanf () from /usr/lib/libc.so.12
    #3  0xbbad67a9 in swscanf () from /usr/lib/libc.so.12
    #4  0x0804ac10 in stfl_widget_getkv_int (w=0x8062580, key=0x8053f20, 
defval=1) at base.c:227
    #5  0x080500bf in wt_table_prepare (w=0x8062480, f=0x805c040) at 
widgets/wt_table.c:107
    #6  0x0804e52a in wt_box_prepare (w=0x8062000, f=0x805c040) at 
widgets/wt_box.c:61
    #7  0x0804b3c5 in stfl_form_run (f=0x805c040, timeout=0) at base.c:494
    #8  0x0804986c in stfl_run (f=0x805c040, timeout=0) at public.c:55
    #9  0x080496ec in main () at example.c:46
    (gdb)

Problem with swscanf()? The code there (base.c) looks ok... So I decided
to try with a simple program myself. The program is:

    #include <stdio.h>
    #include <wchar.h>

    int
    main(int argc, char *argv[])
    {
            int ret;
            int num;
            wchar_t *wstr = L"5";
            wchar_t *wfmt = L"%d";

            ret = swscanf(wstr, wfmt, &num);

            printf("ret: %d\n", ret);

            return ret;
    }

So I compiled, ran and debugged it:

    $ cc -o test test.c
    $ ./test
    Memory fault (core dumped)
    $ gdb -c test.core test
    ...
    Program terminated with signal 11, Segmentation fault.
    #0  0xbbb671cb in __fgetwc_unlock () from /usr/lib/libc.so.12
    (gdb) bt
    #0  0xbbb671cb in __fgetwc_unlock () from /usr/lib/libc.so.12
    #1  0xbbb61fb1 in __vfwscanf_unlocked () from /usr/lib/libc.so.12
    #2  0xbbb61c10 in vswscanf () from /usr/lib/libc.so.12
    #3  0xbbb327a9 in swscanf () from /usr/lib/libc.so.12
    #4  0x0804873d in main ()
    (gdb) quit

The same error...

I'm not a C expert (well, I'm not event a C programmer!), but I couldn't
find any error in the above program. I tried with other examples from
internet, and I got the same error.

Looking for a solution, I found in pkgsrc-users list that people have
had a similar problem when trying to build Amaya 10:

http://mail-index.netbsd.org/pkgsrc-users/2008/09/13/msg008031.html

Any idea? Could it be a lower-level problem? The backtrace says
something about __fgetwc_unlock().

NetBSD 4.0 here. Same error in port-xen and port-i386.

Thank you very much!

-- 
Silas Silva


Home | Main Index | Thread Index | Old Index