diff options
author | Michael Kaufmann <mail@michael-kaufmann.ch> | 2016-02-05 21:15:43 +0100 |
---|---|---|
committer | Jay Satiro <raysatiro@yahoo.com> | 2016-02-06 17:51:51 -0500 |
commit | 9e7fcd4291425a528075e6e8e8a459e2ee063463 (patch) | |
tree | 5328c2268b6a69483f50bb687d11f7e4c83dbd07 /lib/idn_win32.c | |
parent | c71b6a2795791f73fd6ca62abebc74da7104d8e6 (diff) | |
download | curl-9e7fcd4291425a528075e6e8e8a459e2ee063463.tar.gz |
idn_win32: Better error checking
.. also fix a conversion bug in the unused function
curl_win32_ascii_to_idn().
And remove wprintfs on error (Jay).
Bug: https://github.com/curl/curl/pull/637
Diffstat (limited to 'lib/idn_win32.c')
-rw-r--r-- | lib/idn_win32.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/lib/idn_win32.c b/lib/idn_win32.c index 5b79ff7b2..96b4e2267 100644 --- a/lib/idn_win32.c +++ b/lib/idn_win32.c @@ -65,44 +65,40 @@ WINBASEAPI int WINAPI IdnToUnicode(DWORD dwFlags, #define IDN_MAX_LENGTH 255 int curl_win32_idn_to_ascii(const char *in, char **out); -int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8); +int curl_win32_ascii_to_idn(const char *in, char **out); int curl_win32_idn_to_ascii(const char *in, char **out) { + int ret = 0; wchar_t *in_w = Curl_convert_UTF8_to_wchar(in); if(in_w) { wchar_t punycode[IDN_MAX_LENGTH]; - if(IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH) == 0) { - wprintf(L"ERROR %d converting to Punycode\n", GetLastError()); - free(in_w); - return 0; - } + int chars = IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH); free(in_w); - - *out = Curl_convert_wchar_to_UTF8(punycode); - if(!*out) - return 0; + if(chars) { + *out = Curl_convert_wchar_to_UTF8(punycode); + if(*out) + ret = 1; /* success */ + } } - return 1; + return ret; } -int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8) +int curl_win32_ascii_to_idn(const char *in, char **out) { - (void)in_len; /* unused */ - if(in) { - WCHAR unicode[IDN_MAX_LENGTH]; - - if(IdnToUnicode(0, (wchar_t *)in, -1, unicode, IDN_MAX_LENGTH) == 0) { - wprintf(L"ERROR %d converting to Punycode\n", GetLastError()); - return 0; - } - else { - *out_utf8 = Curl_convert_wchar_to_UTF8(unicode); - if(!*out_utf8) - return 0; + int ret = 0; + wchar_t *in_w = Curl_convert_UTF8_to_wchar(in); + if(in_w) { + wchar_t unicode[IDN_MAX_LENGTH]; + int chars = IdnToUnicode(0, in_w, wcslen(in_w)+1, unicode, IDN_MAX_LENGTH); + free(in_w); + if(chars) { + *out = Curl_convert_wchar_to_UTF8(unicode); + if(*out) + ret = 1; /* success */ } } - return 1; + return ret; } #endif /* USE_WIN32_IDN */ |