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

Address -Wfortify-source warnings. #138

Merged
merged 1 commit into from
May 15, 2024

Conversation

cristian64
Copy link
Collaborator

A number of constexpr checks have been added to the compareMemoryAsNumbersWithType<T>() template function so that the compiler can determine that type conversions are only performed between compatible types (i.e. types of the same width).

In addition, Common::bit_cast is now used for type conversion (instead of raw memcpy()).

-Wfortify-source; previously suppressed; has been re-enabled now. Note that this is a Clang-specific warning type.

A number of `constexpr` checks have been added to the
`compareMemoryAsNumbersWithType<T>()` template function so that the
compiler can determine that type conversions are only performed between
compatible types (i.e. types of the same width).

In addition, `Common::bit_cast` is now used for type conversion (instead
of raw `memcpy()`).

`-Wfortify-source`; previously suppressed; has been re-enabled now. Note
that this is a Clang-specific warning type.
break;
}
default:
assert(0 && "Unexpected type size");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert was introduced in e9c0e22, and it was not correct. T could be char, and it's a valid case where it simply does not require any byte swapping in any case (for obvious reasons).

I only discovered this after converting the assert to static_assert (moved towards the top of the function now).

@dreamsyntax dreamsyntax merged commit 8e5fd21 into aldelaro5:master May 15, 2024
4 checks passed
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