Skip to content

Commit

Permalink
Changed suppression of signed/unsigned mismatch to explicit casts.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lastique committed Aug 25, 2024
1 parent bfb0636 commit 5dc58be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ system::error_code dir_itr_increment(dir_itr_imp& imp, fs::path& filename, fs::f
if (!NT_SUCCESS(status))
{
dir_itr_close(imp);
if (status == STATUS_NO_MORE_FILES)
if (BOOST_NTSTATUS_EQ(status, STATUS_NO_MORE_FILES))
goto done;

return system::error_code(translate_ntstatus(status), system::system_category());
Expand Down Expand Up @@ -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
// (which is presumably equivalent to STATUS_NO_SUCH_FILE) which we
// 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;

return error_code(translate_ntstatus(status), system_category());
Expand Down Expand Up @@ -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();
}
else if (status == STATUS_NOT_IMPLEMENTED)
else if (BOOST_NTSTATUS_EQ(status, STATUS_NOT_IMPLEMENTED))
{
symlink_ft = dir_it->symlink_file_type(ec);
}
Expand Down Expand Up @@ -1615,7 +1615,7 @@ void recursive_directory_iterator_increment(recursive_directory_iterator& it, sy
{
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);
}
Expand Down
13 changes: 6 additions & 7 deletions src/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ typedef boost::winapi::DWORD_ err_t;
#define BOOST_ERROR_ALREADY_EXISTS boost::winapi::ERROR_ALREADY_EXISTS_
#define BOOST_ERROR_NOT_SUPPORTED boost::winapi::ERROR_NOT_SUPPORTED_

#if defined(__GNUC__)
// STATUS_* constants defined in ntstatus.h are defined as DWORDs, and NTSTATUS is long. This results
// in signed/unsigned mismatch warnings emitted by gcc and clang. Consider that a platform bug.
#pragma GCC diagnostic ignored "-Wsign-compare"
#endif
// STATUS_* constants defined in ntstatus.h in some SDKs are defined as DWORDs, and NTSTATUS is LONG.
// This results 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)

// Note: Legacy MinGW doesn't have ntstatus.h and doesn't define NTSTATUS error codes other than STATUS_SUCCESS.
#if !defined(NT_SUCCESS)
Expand Down Expand Up @@ -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
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 ||
status == STATUS_BAD_NETWORK_PATH || status == STATUS_BAD_NETWORK_NAME;
return BOOST_NTSTATUS_EQ(status, STATUS_NO_SUCH_FILE) || BOOST_NTSTATUS_EQ(status, STATUS_OBJECT_NAME_NOT_FOUND) ||
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
Expand Down
4 changes: 2 additions & 2 deletions src/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
if (BOOST_UNLIKELY(!nt_create_file))
return STATUS_NOT_IMPLEMENTED;
return static_cast< boost::winapi::NTSTATUS_ >(STATUS_NOT_IMPLEMENTED);

unicode_string obj_name = {};
obj_name.Buffer = const_cast< wchar_t* >(p.c_str());
Expand Down Expand Up @@ -1591,7 +1591,7 @@ boost::winapi::NTSTATUS_ nt_create_file_handle_at
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
filesystem::detail::atomic_store_relaxed(g_no_obj_dont_reparse, true);
Expand Down

0 comments on commit 5dc58be

Please sign in to comment.