win: set fallback message if FormatMessage fails
FormatMessage can fail, e.g. with ERROR_MUI_FILE_NOT_FOUND. In this case no error message was set and uv_dlerror wrongly returned "no error". With this patch the fallback error message "error: <errorno>" is generated when FormatMessage fails. PR-URL: https://github.com/libuv/libuv/pull/59 Reviewed-By: Bert Belder <bertbelder@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
4298c1fb2c
commit
6eb2eaa753
28
src/win/dl.c
28
src/win/dl.c
@ -69,17 +69,37 @@ const char* uv_dlerror(uv_lib_t* lib) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void uv__format_fallback_error(uv_lib_t* lib, int errorno){
|
||||||
|
DWORD_PTR args[1] = { (DWORD_PTR) errorno };
|
||||||
|
LPSTR fallback_error = "error: %1!d!";
|
||||||
|
|
||||||
|
FormatMessageA(FORMAT_MESSAGE_FROM_STRING |
|
||||||
|
FORMAT_MESSAGE_ARGUMENT_ARRAY |
|
||||||
|
FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||||
|
fallback_error, 0, 0,
|
||||||
|
(LPSTR) &lib->errmsg,
|
||||||
|
0, (va_list*) args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int uv__dlerror(uv_lib_t* lib, int errorno) {
|
static int uv__dlerror(uv_lib_t* lib, int errorno) {
|
||||||
|
DWORD res;
|
||||||
|
|
||||||
if (lib->errmsg) {
|
if (lib->errmsg) {
|
||||||
LocalFree((void*)lib->errmsg);
|
LocalFree((void*)lib->errmsg);
|
||||||
lib->errmsg = NULL;
|
lib->errmsg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorno) {
|
if (errorno) {
|
||||||
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
|
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,
|
||||||
(LPSTR)&lib->errmsg, 0, NULL);
|
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
|
||||||
|
(LPSTR) &lib->errmsg, 0, NULL);
|
||||||
|
if (!res) {
|
||||||
|
uv__format_fallback_error(lib, errorno);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorno ? -1 : 0;
|
return errorno ? -1 : 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user