Skip to content

Commit

Permalink
Added C++ style static casts
Browse files Browse the repository at this point in the history
  • Loading branch information
pbentes committed Dec 20, 2024
1 parent f36a53f commit 0123dc3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Arena.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void arenaDestroy(Arena* arena);
#include <new>

Arena* arenaCreate(size_t size) {
Arena* arena = (Arena*)malloc(sizeof(Arena));
Arena* arena = static_cast<Arena*>(malloc(sizeof(Arena)));
if (!arena) {
throw std::bad_alloc();
}
Expand All @@ -40,8 +40,8 @@ void arenaDestroy(Arena* arena);
void* arenaAlloc(Arena* arena, unsigned int size) {
void* ret = arena->index;

arena->index = (char*)arena->index + size;
if (arena->index > (char*)arena->buffer + arena->size)
arena->index = static_cast<char*>(arena->index) + size;
if (arena->index > static_cast<char*>(arena->buffer) + arena->size)
return nullptr;

return ret;
Expand Down
6 changes: 3 additions & 3 deletions tests/src/HelloTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ TEST(Arena, Create) {

TEST(Arena, Alloc) {
Arena* arena = arenaCreate();
int* i = (int*)arenaAlloc(arena, sizeof(int));
int* i = static_cast<int*>(arenaAlloc(arena, sizeof(int)));
ASSERT_NE(i, nullptr);
}

TEST(Arena, Clear) {
Arena* arena = arenaCreate();

int* i = (int*)arenaAlloc(arena, sizeof(int));
int* i = static_cast<int*>(arenaAlloc(arena, sizeof(int)));
arenaClear(arena);
int* d = (int*)arenaAlloc(arena, sizeof(int));
int* d = static_cast<int*>(arenaAlloc(arena, sizeof(int)));

ASSERT_EQ(i, d);
}

0 comments on commit 0123dc3

Please sign in to comment.