tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: swscanf() causing Memory Fault
In article <20081116012924.GC19936%red.tifa.renegado@localhost>,
Silas Silva <silasdb%gmail.com@localhost> wrote:
>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!
Index: vswscanf.c
===================================================================
RCS file: /cvsroot/src/lib/libc/stdio/vswscanf.c,v
retrieving revision 1.3
diff -u -u -r1.3 vswscanf.c
--- vswscanf.c 2 Dec 2005 13:51:22 -0000 1.3
+++ vswscanf.c 16 Nov 2008 03:14:53 -0000
@@ -90,6 +90,7 @@
return (EOF);
}
_FILEEXT_SETUP(&f, &fext);
+ (void)memset(WCIO_GET(&f), 0, sizeof(struct wchar_io_data));
f._file = -1;
f._flags = __SRD;
f._bf._base = f._p = (unsigned char *)mbstr;
christos
Home |
Main Index |
Thread Index |
Old Index