Downgrade some casts

Do a quick sweep through the codebase to eliminate some reinterpret_cast<>s
where less fire power would do just fine.
This commit is contained in:
Nathaniel Wesley Filardo
2022-03-17 17:55:47 +00:00
committed by Nathaniel Wesley Filardo
parent 62cce1a20e
commit 4ad99d7392
4 changed files with 11 additions and 16 deletions

View File

@@ -88,16 +88,12 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
expected_size);
failed = true;
}
if (
(static_cast<size_t>(reinterpret_cast<uintptr_t>(p) % align) != 0) &&
(size != 0))
if (((address_cast(p) % align) != 0) && (size != 0))
{
INFO("Address is {}, but required to be aligned to {}.\n", p, align);
failed = true;
}
if (
static_cast<size_t>(
reinterpret_cast<uintptr_t>(p) % natural_alignment(size)) != 0)
if ((address_cast(p) % natural_alignment(size)) != 0)
{
INFO(
"Address is {}, but should have natural alignment to {}.\n",

View File

@@ -69,8 +69,8 @@ extern "C" void abort()
void check_size(size_t size)
{
START_TEST("checking {}-byte memcpy", size);
auto* s = reinterpret_cast<unsigned char*>(my_malloc(size + 1));
auto* d = reinterpret_cast<unsigned char*>(my_malloc(size + 1));
auto* s = static_cast<unsigned char*>(my_malloc(size + 1));
auto* d = static_cast<unsigned char*>(my_malloc(size + 1));
d[size] = 0;
s[size] = 255;
for (size_t start = 0; start < size; start++)
@@ -115,8 +115,8 @@ void check_bounds(size_t size, size_t out_of_bounds)
{
START_TEST(
"memcpy bounds, size {}, {} bytes out of bounds", size, out_of_bounds);
auto* s = reinterpret_cast<unsigned char*>(my_malloc(size));
auto* d = reinterpret_cast<unsigned char*>(my_malloc(size));
auto* s = static_cast<unsigned char*>(my_malloc(size));
auto* d = static_cast<unsigned char*>(my_malloc(size));
for (size_t i = 0; i < size; ++i)
{
s[i] = static_cast<unsigned char>(i);