[prev in list] [next in list] [prev in thread] [next in thread]
List: mingw-users
Subject: Re: [Mingw-users] asprintf missing,
From: Jonathan Schleifer <js-mingw-users () webkeks ! org>
Date: 2008-12-19 13:05:33
Message-ID: 20081219140533.2c14e1d9 () webkeks ! org
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
Ok, I found out how to reprodue the problem. The -O2 flag is causing
the problem. Take a look at this:
asgard:/tmp$ cat asprintf.c
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int
asprintf(char **strp, const char *fmt, ...)
{
int size;
va_list args;
va_start(args, fmt);
if ((size = vsnprintf(NULL, 0, fmt, args)) < 0)
return size;
if ((*strp = malloc((size_t)size + 1)) == NULL)
return -1;
return vsnprintf(*strp, (size_t)size + 1, fmt, args);
}
int main()
{
char *x;
printf("ret: %d\n", asprintf(&x, "hello"));
printf("ptr: %p\n", x);
puts(x);
return 0;
}
asgard:/tmp$ mingw32-gcc asprintf.c
asgard:/tmp$ wine a.exe
ret: 5
ptr: 00110888
hello
Until here, everything works as expected. But look now at this (still
the same file):
asgard:/tmp$ mingw32-gcc -O2 asprintf.c
asgard:/tmp$ wine a.exe
ret: -1
ptr: 00000000
wine: Unhandled page fault on read access to 0x00000000 at address 0xb7dd7ab3 (thread \
0009), starting debugger... Unhandled exception: page fault on read access to \
0x00000000 in 32-bit code (0xb7dd7ab3). Register dump:
CS:0073 SS:007b DS:007b ES:007b FS:0033 GS:003b
EIP:b7dd7ab3 ESP:0060fe5c EBP:0060fe88 EFLAGS:00010246( - 00 -RIZP1)
EAX:00000000 EBX:7ebe5d98 ECX:00000000 EDX:00000000
ESI:00000000 EDI:00401130
Stack dump:
0x0060fe5c: 7ebc5995 00000000 00403033 0060fe94
0x0060fe6c: 0060fe98 000000fc 7ebe5d98 0060fea8
0x0060fe7c: 7eeb19c0 7ffdf000 00401130 0060feb8
0x0060fe8c: 004013d0 00000000 00000000 0060feb8
0x0060fe9c: 0040139a 7ebebdc8 00401130 0060fec8
0x0060feac: 7ebbc51c 00000000 0060fed0 0060fef8
Backtrace:
=>1 0xb7dd7ab3 strlen+0x33() in libc.so.6 (0x0060fe88)
2 0x004013d0 in a (+0x13d0) (0x0060feb8)
3 0x004010b6 in a (+0x10b6) (0x0060fef8)
4 0x00401148 in a (+0x1148) (0x0060ff08)
5 0x7ee74d97 start_process+0xc7(arg=0x0) \
[/tmp/wine-1.1.1/dlls/kernel32/process.c:904] in kernel32 (0x0060ffe8) 6 0xb7ed3587 \
wine_switch_to_stack+0x17() in libwine.so.1 (0x00000000) 0xb7dd7ab3 strlen+0x33 in \
libc.so.6: movl 0x0(%eax),%ecx Modules:
Module Address Debug info Name (15 modules)
PE 400000- 40a000 Export a
ELF 7bf00000-7bf03000 Deferred <wine-loader>
ELF 7eb99000-7ec01000 Deferred msvcrt<elf>
\-PE 7ebb0000-7ec01000 \ msvcrt
ELF 7ee01000-7ef2e000 Dwarf kernel32<elf>
\-PE 7ee20000-7ef2e000 \ kernel32
ELF 7ef2e000-7ef38000 Deferred libnss_files.so.2
ELF 7ef38000-7ef5d000 Deferred libm.so.6
ELF 7ef5d000-7f000000 Deferred ntdll<elf>
\-PE 7ef70000-7f000000 \ ntdll
ELF b7d68000-b7d6c000 Deferred libdl.so.2
ELF b7d6c000-b7e9a000 Export libc.so.6
ELF b7e9a000-b7eb1000 Deferred libpthread.so.0
ELF b7ecc000-b8002000 Dwarf libwine.so.1
ELF b8003000-b801f000 Deferred ld-linux.so.2
Threads:
process tid prio (all id:s are in hex)
00000008 (D) Z:\tmp\a.exe
00000009 0 <==
0000000c
00000013 0
00000012 0
0000000e 0
0000000d 0
0000000f
00000015 0
00000014 0
00000011 0
00000010 0
Backtrace:
=>1 0xb7dd7ab3 strlen+0x33() in libc.so.6 (0x0060fe88)
2 0x004013d0 in a (+0x13d0) (0x0060feb8)
3 0x004010b6 in a (+0x10b6) (0x0060fef8)
4 0x00401148 in a (+0x1148) (0x0060ff08)
5 0x7ee74d97 start_process+0xc7(arg=0x0) \
[/tmp/wine-1.1.1/dlls/kernel32/process.c:904] in kernel32 (0x0060ffe8) 6 0xb7ed3587 \
wine_switch_to_stack+0x17() in libwine.so.1 (0x00000000)
So it seems mingw32-gcc uses a different vsnprintf when using -O2?
--
Jonathan
["signature.asc" (application/pgp-signature)]
------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
MinGW-users@lists.sourceforge.net
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic