[MinGW-Notify] [mingw] #39687: wcsrtombs with NULL dest pointer doesn't ignore len parameter

Back to archive index
MinGW Notification List mingw****@lists*****
Wed Nov 13 00:11:51 JST 2019


#39687: wcsrtombs with NULL dest pointer doesn't ignore len parameter



  Open Date: 2019-10-19 17:38
Last Update: 2019-11-12 15:11

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/39687
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=39687

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2019-11-12 15:11 Updated by: keith

Comment:

The problem is indeed the Microsoft setlocale() limitation, (which, although
Microsoft's documentation doesn't acknowledge it as such, is clearly a bug).
The clue is in the Locale: C output, following the conditional call which
becomes equivalent to setlocale( LC_CTYPE, "English_United Kingdom.65001" );
the failure to change the locale setting, from the initial "C" state, is a
clear indication that the 65001 (UTF-8) codeset specification has been
rejected.

The ideal solution would be to have a correctly working setlocale()
implementation, but Microsoft will never provide that, particularly in the case
of any legacy Windows version, which MinGW still endeavours to support. Next
best would be a MinGW replacement setlocale() implementation, (which could also
address other failings of the Microsoft implementation), but this would require
significant development effort, and must, therefore, be considered only as a
longer term development objective. In the shorter term, I propose to adapt the
MinGW replacements for wcrtomb() and wcsrtombs(), such that they will initially
identify a potential codeset identity from the string returned by setlocale(
LC_CTYPE, NULL ), (as they do currently), but then override that by inspection
of getenv( "LC_ALL" ), getenv( "LC_CTYPE" ), or getenv( "LANG" ), in that
order, and taking the first non-NULL, if any, and then if, and only if, the
string returned by setlocale( LC_CTYPE, NULL ) is a verbatim match for that
returned by setlocale( LC_CTYPE, "" ), and any overriding codeset, so
identified, is confirmed as having a non-zero encoding length, by GetCPInfo(
codeset, &info ).



---------------------------------------------------------------------
Ticket Status:

      Reporter: gallickgunner
         Owner: keith
          Type: Issues
        Status: Open [Owner assigned]
      Priority: 5 - Medium
     MileStone: (None)
     Component: WSL
      Severity: 5 - Medium
    Resolution: None
---------------------------------------------------------------------

Ticket details:

I'm using MinGW-gcc-6.3.0. The wcsrtombs() function as mentioned in the docs on
cppreference should return the number of bytes that would have been written to
src. However it doesn't do so on my end. It seems the implementation doesn't
ignore the length parameter when dest is passed as NULL? A similar issue was
reported and presumably fixed for the Mingw-w64 on the sourceforge site
Currently working around by passing INT_MAX as the length parameter, so it
finishes within the limit and returns the size.

I apologize in advance if this is just an issue from my end or if any other
info is missing. First time submitting a ticket :)



-- 
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN

Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net

URL for this Ticket:
    https://osdn.net/projects/mingw/ticket/39687
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=39687



More information about the MinGW-Notify mailing list
Back to archive index