diff options
author | Keith Marshall <keithmarshall@@users.sf.net> | 2009-09-30 00:43:50 +0400 |
---|---|---|
committer | Keith Marshall <keithmarshall@@users.sf.net> | 2009-09-30 00:43:50 +0400 |
commit | e97ad66a846702f4fb66a2ea8a5191dc97b3e9dc (patch) | |
tree | 5037f4e43f807e66705583d076c00d89222cda44 /winsup/mingw/mingwex | |
parent | 50e4e69c42d6b267997b62a261e1cf7d5b342d8c (diff) |
Make MinGW printf() "%p" format compatible with MSVCRT scanf().
Diffstat (limited to 'winsup/mingw/mingwex')
-rw-r--r-- | winsup/mingw/mingwex/stdio/pformat.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/winsup/mingw/mingwex/stdio/pformat.c b/winsup/mingw/mingwex/stdio/pformat.c index a59d5130f..55972fc45 100644 --- a/winsup/mingw/mingwex/stdio/pformat.c +++ b/winsup/mingw/mingwex/stdio/pformat.c @@ -2021,9 +2021,22 @@ int __pformat( int flags, void *dest, int max, const char *fmt, va_list argv ) case 'p': /* - * Pointer argument; format as hexadecimal, with `0x' prefix... + * Pointer argument; format as hexadecimal, subject to... */ - stream.flags |= PFORMAT_HASHED; + if( (state == PFORMAT_INIT) && (stream.flags == flags) ) + { + /* Here, the user didn't specify any particular + * formatting attributes. We must choose a default + * which will be compatible with Microsoft's (broken) + * scanf() implementation, (i.e. matching the default + * used by MSVCRT's printf(), which appears to resemble + * "%0.8X" for 32-bit pointers); in particular, we MUST + * NOT adopt a GNU-like format resembling "%#x", because + * Microsoft's scanf() will choke on the "0x" prefix. + */ + stream.flags |= PFORMAT_ZEROFILL; + stream.precision = 2 * sizeof( uintptr_t ); + } argval.__pformat_ullong_t = va_arg( argv, uintptr_t ); __pformat_xint( 'x', argval, &stream ); goto format_scan; |