Changed suppression of signed/unsigned mismatch to explicit casts.

Turns out, suppressing -Wsign-compare doesn't work on gcc 8 in MinGW-w64
at least in one instance. So we have to do it the hard way and explicitly
cast NTSTATUS values on every comparison.
This commit is contained in:
Andrey Semashev 2024-08-25 18:09:53 +03:00
parent bfb06365b3
commit 5dc58be3cd
3 changed files with 12 additions and 13 deletions

View File

@ -799,7 +799,7 @@ system::error_code dir_itr_increment(dir_itr_imp& imp, fs::path& filename, fs::f
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
{ {
dir_itr_close(imp); dir_itr_close(imp);
if (status == STATUS_NO_MORE_FILES) if (BOOST_NTSTATUS_EQ(status, STATUS_NO_MORE_FILES))
goto done; goto done;
return system::error_code(translate_ntstatus(status), system::system_category()); return system::error_code(translate_ntstatus(status), system::system_category());
@ -1047,7 +1047,7 @@ system::error_code dir_itr_create(boost::intrusive_ptr< detail::dir_itr_imp >& i
// causes a ERROR_FILE_NOT_FOUND error returned from FindFirstFileW // causes a ERROR_FILE_NOT_FOUND error returned from FindFirstFileW
// (which is presumably equivalent to STATUS_NO_SUCH_FILE) which we // (which is presumably equivalent to STATUS_NO_SUCH_FILE) which we
// do not consider an error. It is treated as eof instead. // do not consider an error. It is treated as eof instead.
if (status == STATUS_NO_MORE_FILES || status == STATUS_NO_SUCH_FILE) if (BOOST_NTSTATUS_EQ(status, STATUS_NO_MORE_FILES) || BOOST_NTSTATUS_EQ(status, STATUS_NO_SUCH_FILE))
goto done; goto done;
return error_code(translate_ntstatus(status), system_category()); return error_code(translate_ntstatus(status), system_category());
@ -1520,7 +1520,7 @@ void recursive_directory_iterator_increment(recursive_directory_iterator& it, sy
{ {
symlink_ft = detail::status_by_handle(direntry_handle.get(), dir_it->path(), &ec).type(); symlink_ft = detail::status_by_handle(direntry_handle.get(), dir_it->path(), &ec).type();
} }
else if (status == STATUS_NOT_IMPLEMENTED) else if (BOOST_NTSTATUS_EQ(status, STATUS_NOT_IMPLEMENTED))
{ {
symlink_ft = dir_it->symlink_file_type(ec); symlink_ft = dir_it->symlink_file_type(ec);
} }
@ -1615,7 +1615,7 @@ void recursive_directory_iterator_increment(recursive_directory_iterator& it, sy
{ {
goto get_file_type_by_handle; goto get_file_type_by_handle;
} }
else if (status == STATUS_NOT_IMPLEMENTED) else if (BOOST_NTSTATUS_EQ(status, STATUS_NOT_IMPLEMENTED))
{ {
ft = dir_it->file_type(ec); ft = dir_it->file_type(ec);
} }

View File

@ -51,11 +51,9 @@ typedef boost::winapi::DWORD_ err_t;
#define BOOST_ERROR_ALREADY_EXISTS boost::winapi::ERROR_ALREADY_EXISTS_ #define BOOST_ERROR_ALREADY_EXISTS boost::winapi::ERROR_ALREADY_EXISTS_
#define BOOST_ERROR_NOT_SUPPORTED boost::winapi::ERROR_NOT_SUPPORTED_ #define BOOST_ERROR_NOT_SUPPORTED boost::winapi::ERROR_NOT_SUPPORTED_
#if defined(__GNUC__) // STATUS_* constants defined in ntstatus.h in some SDKs are defined as DWORDs, and NTSTATUS is LONG.
// STATUS_* constants defined in ntstatus.h are defined as DWORDs, and NTSTATUS is long. This results // This results in signed/unsigned mismatch warnings emitted by gcc and clang. Consider that a platform bug.
// in signed/unsigned mismatch warnings emitted by gcc and clang. Consider that a platform bug. #define BOOST_NTSTATUS_EQ(x, y) static_cast< boost::winapi::ULONG_ >(x) == static_cast< boost::winapi::ULONG_ >(y)
#pragma GCC diagnostic ignored "-Wsign-compare"
#endif
// Note: Legacy MinGW doesn't have ntstatus.h and doesn't define NTSTATUS error codes other than STATUS_SUCCESS. // Note: Legacy MinGW doesn't have ntstatus.h and doesn't define NTSTATUS error codes other than STATUS_SUCCESS.
#if !defined(NT_SUCCESS) #if !defined(NT_SUCCESS)
@ -177,8 +175,9 @@ inline boost::winapi::DWORD_ translate_ntstatus(boost::winapi::NTSTATUS_ status)
//! Tests if the NTSTATUS indicates that the file is not found //! Tests if the NTSTATUS indicates that the file is not found
inline bool not_found_ntstatus(boost::winapi::NTSTATUS_ status) noexcept inline bool not_found_ntstatus(boost::winapi::NTSTATUS_ status) noexcept
{ {
return status == STATUS_NO_SUCH_FILE || status == STATUS_OBJECT_NAME_NOT_FOUND || status == STATUS_OBJECT_PATH_NOT_FOUND || return BOOST_NTSTATUS_EQ(status, STATUS_NO_SUCH_FILE) || BOOST_NTSTATUS_EQ(status, STATUS_OBJECT_NAME_NOT_FOUND) ||
status == STATUS_BAD_NETWORK_PATH || status == STATUS_BAD_NETWORK_NAME; BOOST_NTSTATUS_EQ(status, STATUS_OBJECT_PATH_NOT_FOUND) || BOOST_NTSTATUS_EQ(status, STATUS_BAD_NETWORK_PATH) ||
BOOST_NTSTATUS_EQ(status, STATUS_BAD_NETWORK_NAME);
} }
#endif #endif

View File

@ -1559,7 +1559,7 @@ boost::winapi::NTSTATUS_ nt_create_file_handle_at
{ {
NtCreateFile_t* nt_create_file = filesystem::detail::atomic_load_relaxed(nt_create_file_api); NtCreateFile_t* nt_create_file = filesystem::detail::atomic_load_relaxed(nt_create_file_api);
if (BOOST_UNLIKELY(!nt_create_file)) if (BOOST_UNLIKELY(!nt_create_file))
return STATUS_NOT_IMPLEMENTED; return static_cast< boost::winapi::NTSTATUS_ >(STATUS_NOT_IMPLEMENTED);
unicode_string obj_name = {}; unicode_string obj_name = {};
obj_name.Buffer = const_cast< wchar_t* >(p.c_str()); obj_name.Buffer = const_cast< wchar_t* >(p.c_str());
@ -1591,7 +1591,7 @@ boost::winapi::NTSTATUS_ nt_create_file_handle_at
0u // EaLength 0u // EaLength
); );
if (BOOST_UNLIKELY(status == STATUS_INVALID_PARAMETER && (obj_attrs.Attributes & OBJ_DONT_REPARSE) != 0u)) if (BOOST_UNLIKELY(BOOST_NTSTATUS_EQ(status, STATUS_INVALID_PARAMETER) && (obj_attrs.Attributes & OBJ_DONT_REPARSE) != 0u))
{ {
// OBJ_DONT_REPARSE is supported since Windows 10, retry without it // OBJ_DONT_REPARSE is supported since Windows 10, retry without it
filesystem::detail::atomic_store_relaxed(g_no_obj_dont_reparse, true); filesystem::detail::atomic_store_relaxed(g_no_obj_dont_reparse, true);