1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

tool_cb_wrt: Silence function cast compiler warning

Commit 5bfaa86ceb introduced a new
compiler warning on Windows cross compilation with GCC. See below
for an example of the warning from the autobuild logs (whitespace
edited to fit):

/src/tool_cb_wrt.c:175:9: warning: cast from function call of type
    'intptr_t {aka long long int}' to non-matching type 'void *'
    [-Wbad-function-cast]
(HANDLE) _get_osfhandle(fileno(outs->stream)),
^

Store the return value from _get_osfhandle() in an intermediate
variable and cast the variable in WriteConsoleW() rather than the
function call directly to avoid a compiler warning.

In passing, also add inspection of the MultiByteToWideChar() return
value and return failure in case an error is reported.

Closes #3263
Reviewed-by: Marcel Raad <Marcel.Raad@teamviewer.com>
Reviewed-by: Viktor Szakats <commit@vszakats.net>
This commit is contained in:
Daniel Gustafsson 2018-11-12 20:54:07 +01:00
parent 42fd235040
commit 2f5f31bb57

View File

@ -161,6 +161,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
DWORD in_len = (DWORD)(sz * nmemb); DWORD in_len = (DWORD)(sz * nmemb);
wchar_t* wc_buf; wchar_t* wc_buf;
DWORD wc_len; DWORD wc_len;
intptr_t fhnd;
/* calculate buffer size for wide characters */ /* calculate buffer size for wide characters */
wc_len = MultiByteToWideChar(CP_UTF8, 0, buffer, in_len, NULL, 0); wc_len = MultiByteToWideChar(CP_UTF8, 0, buffer, in_len, NULL, 0);
@ -170,9 +171,15 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
/* calculate buffer size for multi-byte characters */ /* calculate buffer size for multi-byte characters */
wc_len = MultiByteToWideChar(CP_UTF8, 0, buffer, in_len, wc_buf, wc_len); wc_len = MultiByteToWideChar(CP_UTF8, 0, buffer, in_len, wc_buf, wc_len);
if(!wc_len) {
free(wc_buf);
return failure;
}
fhnd = _get_osfhandle(fileno(outs->stream));
if(!WriteConsoleW( if(!WriteConsoleW(
(HANDLE) _get_osfhandle(fileno(outs->stream)), (HANDLE) fhnd,
wc_buf, wc_buf,
wc_len, wc_len,
&wc_len, &wc_len,