From 2147ed71efcb2af43382a285a8df272f22ba2c95 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 12 Jun 2025 14:04:17 +0200 Subject: [PATCH] Common: Require explicit handle validation Using operator bool() hid ambiguity when handle was polymorfic with bool. Using operator!() reqired !! to test for validity which results in awkward code. Signed-off-by: Simon Rozman --- include/WinStd/WinHTTP.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/WinStd/WinHTTP.h b/include/WinStd/WinHTTP.h index 8d1a8a8b..e32c9a7e 100644 --- a/include/WinStd/WinHTTP.h +++ b/include/WinStd/WinHTTP.h @@ -212,7 +212,7 @@ namespace winstd last_error_saver last_error_save; std::wstring wstr; winstd::library winhttp(LoadLibraryW(L"WINHTTP.DLL")); - if (WINHTTP_ERROR_BASE < num && num <= WINHTTP_ERROR_LAST && winhttp && FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, (HMODULE)winhttp, num, dwLanguageId, wstr, NULL) || + if (WINHTTP_ERROR_BASE < num && num <= WINHTTP_ERROR_LAST && winhttp.valid() && FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, (HMODULE)winhttp, num, dwLanguageId, wstr, NULL) || FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, num, dwLanguageId, wstr, NULL)) { // Stock Windows error messages contain CRLF. Well... Trim all the trailing white space. wstr.erase(wstr.find_last_not_of(L" \t\n\r\f\v") + 1);