From 37f2dc3555c8367a9b88e094bd72e49eef5eaed2 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 26 Nov 2007 22:49:43 +0000 Subject: [PATCH] Some improvements, being upstreamed. (must_use_null_useddefaultchar): New 2007-11-27 Tor Lillqvist * glib/win_iconv.c: Some improvements, being upstreamed. (must_use_null_useddefaultchar): New function, checks for those codepages for which one must pass a NULL lpUsedDefaultChar pointer to WideCharToMultiByte(). (kernel_wctomb): Use it. (kernel_wctomb): Return with E2BIG immediately if bufsize is zero. svn path=/trunk/; revision=5945 --- ChangeLog | 9 +++++++++ glib/win_iconv.c | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 384503b7d..f7e25bb82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-11-27 Tor Lillqvist + + * glib/win_iconv.c: Some improvements, being upstreamed. + (must_use_null_useddefaultchar): New function, checks for those + codepages for which one must pass a NULL lpUsedDefaultChar pointer + to WideCharToMultiByte(). + (kernel_wctomb): Use it. + (kernel_wctomb): Return with E2BIG immediately if bufsize is zero. + 2007-11-27 Tor Lillqvist * glib/gutils.c (_glib_get_locale_dir) [Win32]: Use either diff --git a/glib/win_iconv.c b/glib/win_iconv.c index e61eb0d26..7fb1da2a6 100644 --- a/glib/win_iconv.c +++ b/glib/win_iconv.c @@ -137,6 +137,7 @@ static int name_to_codepage(const char *name); static uint utf16_to_ucs4(const ushort *wbuf); static void ucs4_to_utf16(uint wc, ushort *wbuf, int *wbufsize); static int is_unicode(int codepage); +static int must_use_null_useddefaultchar(int codepage); static void check_utf_bom(rec_iconv_t *cd, ushort *wbuf, int *wbufsize); static char *strrstr(const char *str, const char *token); @@ -1001,6 +1002,18 @@ is_unicode(int codepage) codepage == 65000 || codepage == 65001); } +static int +must_use_null_useddefaultchar(int codepage) +{ + return (codepage == 65000 || codepage == 65001 || + codepage == 50220 || codepage == 50221 || + codepage == 50222 || codepage == 50225 || + codepage == 50227 || codepage == 50229 || + codepage == 52936 || codepage == 54936 || + (codepage >= 57002 && codepage <= 57011) || + codepage == 42); +} + static void check_utf_bom(rec_iconv_t *cd, ushort *wbuf, int *wbufsize) { @@ -1269,9 +1282,11 @@ kernel_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) BOOL usedDefaultChar = 0; int len; + if (bufsize == 0) + return_error(E2BIG); len = WideCharToMultiByte(cv->codepage, 0, (const wchar_t *)wbuf, wbufsize, (char *)buf, bufsize, NULL, - (cv->codepage == 65000 || cv->codepage == 65001) ? NULL : &usedDefaultChar); + must_use_null_useddefaultchar(cv->codepage) ? NULL : &usedDefaultChar); if (len == 0) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)