On 2017/11/11 12:41, David Lee wrote:
Hello,

Tried to compile and run the following C code on Windows (with
gcc/mingw-w64), and it crashed at the swscanf() call:

----

#define __USE_MINGW_ANSI_STDIO 1

#include <stdio.h>

int
main(void)
{
     wchar_t buf[] = L"1 2 3";
     wchar_t field[10];

     swscanf(buf, L"%ls", field); // crash
     wprintf(L"%ls\n", field);

     return 0;
}

----

This is not my original code. The original code is C++ which includes
a C++ header <cstdio> which indirectly defines __USE_MINGW_ANSI_STDIO
(after multiple levels of includes), so originally I didn't define
this constant myself. At least the code here doesn't have C++
influences.

I assumed that, if __USE_MINGW_ANSI_STDIO is defined to be 1, then the
Microsoft convention of interpreting %s" is suppressed and C99
convention rules. It applies to *printf() so I assumed it applies to
*scanf() as well. Instead the program crashed.

The swscanf() call still crashed with different specifiers: "%s", and "%S"

The compiler used were downloaded from here (5.4.0 and 6.4.0)

https://sourceforge.net/projects/mingw-w64/files/Multilib%20Toolchains%28Targetting%20Win32%20and%20Win64%29/

----

Regards,

David Lee.


Debugging in assembly exposes indirection through a null pointer in `mingw-w64-crt/stdio/mingw_wvfscanf.c` around or after line 906:

```
optimize_alloc ((flags & IS_ALLOC_USED) != 0, pstr, str_sz, (wstr - (wchar_t *) *pstr), sizeof (wchar_t));`
```

The CRT libraries of those toolchains were not compiled with debug information. Further investigation might not be possible.

I am not able to reproducible this problem on master. You might want to try a newer version and see if the problem still exists.

--
Best regards,
LH_Mouse


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to