Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Werner Wenzel <werner.wenzel@netcologne.de> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: mbrtoc32 in MinGW-w64 buggy? |
| Date | 2014-03-29 15:09 +0100 |
| Organization | news.netcologne.de |
| Message-ID | <lh6k65$f7c$1@newsreader4.netcologne.de> (permalink) |
| References | <lh6diu$c35$1@newsreader4.netcologne.de> <lh6gkd$sq5$1@dont-email.me> |
Am 29.03.2014 14:08, schrieb Eric Sosman:
> On 3/29/2014 8:16 AM, Werner Wenzel wrote:
>> Running the following MinGW-w64-built code on Windows 7 64 bit crashes
>> with me:
>>
>> #include <stdio.h>
>> #include <uchar.h>
>>
>> int main(void)
>> {
>> mbstate_t mbstate;
>>
>> puts("So far okay ...");
>> mbrtoc32(NULL, "", 1, &mbstate);
>> puts("Not reached due to crash!");
>> return 0;
>> }
>>
>> It should not crash as the problematic line derives from ISO C11 (N1570)
>> 7.28.1.3p2.
>>
>> As far as I can see this issue is caused by
>> \mingw-builds\sources\mingw-w64-v3.1.0\mingw-w64-crt\misc\uchar_mbrtoc32.c,
>>
>> line 32, which--in this special case--dereferences NULL.
>>
>> Is this thought correct or am I missing something?
>
> I am no expert on wide-character utilities and I have not looked
> at the source code, but it looks to me like the `mbstate' variable
> has never been initialized, and so may "contain garbage." What
> happens if you use `mbstate_t mbstate = { 0 };' instead?
>
Actually, it still crashes with "mbstate_t mbstate = { 0 };".
The cited MinGW-w64 code reads as follows:
size_t mbrtoc32 (char32_t *__restrict__ pc32,
const char *__restrict__ s,
size_t n,
mbstate_t *__restrict__ __UNUSED_PARAM(ps))
{
if (*s == 0)
{
*pc32 = 0;
return 0;
}
...
In this special case the empty string (2nd argument) triggers an
assignment of 0 to where pc32 points to and pc32 points nowhere.
In my opinion the arguable code should read:
if (pc32) *pc32 = 0;
Werner
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
mbrtoc32 in MinGW-w64 buggy? Werner Wenzel <werner.wenzel@netcologne.de> - 2014-03-29 13:16 +0100
Re: mbrtoc32 in MinGW-w64 buggy? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-29 09:08 -0400
Re: mbrtoc32 in MinGW-w64 buggy? Werner Wenzel <werner.wenzel@netcologne.de> - 2014-03-29 15:09 +0100
Re: mbrtoc32 in MinGW-w64 buggy? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-29 10:27 -0400
Re: mbrtoc32 in MinGW-w64 buggy? Keith Thompson <kst-u@mib.org> - 2014-03-29 14:38 -0700
Re: mbrtoc32 in MinGW-w64 buggy? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-29 17:44 -0400
Re: mbrtoc32 in MinGW-w64 buggy? Keith Thompson <kst-u@mib.org> - 2014-03-29 16:50 -0700
Re: mbrtoc32 in MinGW-w64 buggy? James Kuyper <jameskuyper@verizon.net> - 2014-03-31 10:54 -0400
Re: mbrtoc32 in MinGW-w64 buggy? James Kuyper <jameskuyper@verizon.net> - 2014-03-29 09:17 -0400
csiph-web