[PATCH] Fix in WideCharToMultiByte

James Hatheway james at macadamian.com
Wed Apr 4 11:11:20 CDT 2001


Hi guys,

I found a bug in WideCharToMultiByte while trying to fix another
issue.  It turns out that the only time the lpUsedDefaultChar variable
was being assigned a value was if a character replacement took place, it was
NEVER being assigned 0 if no conversion took place.  Therefore,
lpUsedDefaultChar was left uninitialized and really confusing the CRT
(look at VC98\CRT\SRC\TZSET.c: _tzset() L215 for a good example.)  Small
test program showing this bug is attached, just compile and run in windows
and then run under WINE.


-James

Test Prog:
int main(int argc, char* argv[])
{
    wchar_t blah[] = L"Hello Jello!";
    char blah2[30];
    int used;


    printf ("used = %d now (before #1)\n", used);
    WideCharToMultiByte( CP_ACP,
                        WC_COMPOSITECHECK |
                        WC_SEPCHARS,
                        blah,
                        -1,
                        blah2,
                        30,
                        NULL,
                        &used );
    printf ("used is now %d, string is blah2=%s\n\n\n", used, blah2);


    used = 5;
    printf ("used = %d now (before #2)\n", used);
    WideCharToMultiByte( CP_ACP,
                         WC_COMPOSITECHECK |
                         WC_SEPCHARS,
                         blah,
                         -1,
                         blah2,
                         30,
                         NULL,
                         &used );
    printf ("used is now %d, string is blah2=%s\n\n\n", used, blah2);

    return 0;
}


Changelog:
  James Hatheway - james at macadamian.com
  In WideCharToMultiByte() lpUsedDefaultChar should be set to 0 if
  no conversions take place.

Modified:
  memory/codepage.c


--
James Hatheway
Software Designer - Macadamian Technologies, Inc.
james at macadamian.com ~ http://www.macadamian.com

  "Man könnte froh sein, wenn die Luft so rein wäre wie das Bier"
  "One could be happy if the air were as pure as the beer"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WideCharToMultiByteFix.diff
Type: application/octet-stream
Size: 567 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20010404/5918b056/WideCharToMultiByteFix.obj


More information about the wine-patches mailing list