Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid implicit cast from size_t to uint32_t #57

Merged
merged 1 commit into from
Jan 17, 2023
Merged

Avoid implicit cast from size_t to uint32_t #57

merged 1 commit into from
Jan 17, 2023

Conversation

travbid
Copy link

@travbid travbid commented Nov 7, 2022

Hello, we have an error on line 42 of path_from_handle.hpp.
With the XCode 14.1 update, the -Wshorten-64-to-32 flag has somehow been enabled in our project and shows this warning when including #include "boost/dll/import.hpp"

In file included from ***/boost/dll/import.hpp:16:
In file included from ***/boost/dll/shared_library.hpp:26:
In file included from ***/boost/dll/detail/posix/shared_library_impl.hpp:13:
***/boost/dll/detail/posix/path_from_handle.hpp:42:59: error: implicit conversion loses integer precision: 'std::size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
const char* image_name = _dyld_get_image_name(i);
~~~~~~~~~~~~~~~~~~~~ ^
1 error generated.

According to the linked docs on line 37, _dyld_get_image_name() takes a uint32_t but here is passed a size_t. With -Wconversion enabled this creates a warning when size_t is a larger type than uint32_t.
_dyld_image_count() returns a uint32_t so I think this can be solved by not casting to size_t in the first place.

Edit: I removed the std:: prefix because mach-o/dyld.h has the type un-prefixed and it seems uint32_t is not part of the C++03 standard.

@travbid travbid marked this pull request as ready for review November 7, 2022 18:45
@apolukhin apolukhin merged commit 0f40791 into boostorg:develop Jan 17, 2023
@apolukhin
Copy link
Member

Many thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants