Skip to content

Address -Wfortify-source warnings.#138

Merged
dreamsyntax merged 1 commit intoaldelaro5:masterfrom
cristian64:fortify_source_warnings
May 15, 2024
Merged

Address -Wfortify-source warnings.#138
dreamsyntax merged 1 commit intoaldelaro5:masterfrom
cristian64:fortify_source_warnings

Conversation

@cristian64
Copy link
Copy Markdown
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
Copy Markdown
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
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