fix(kcp): Various kcp fixes

This commit is contained in:
Daniel Hammer
2025-03-07 23:51:39 +01:00
parent a8f0bb4454
commit 6c5f6ecd47
2 changed files with 6 additions and 9 deletions
@@ -1,4 +1,5 @@
/* /*
* Alloc.cpp
* C++ new/delete operator * C++ new/delete operator
* Copyright (c) 2025 Daniel Hammer * Copyright (c) 2025 Daniel Hammer
*/ */
+5 -9
View File
@@ -24,9 +24,9 @@ namespace kcp
array = nullptr; array = nullptr;
} }
T operator[](std::int64_t position) T operator[](std::size_t position)
{ {
if (position > (sz + 1)) { if (position > (sz - 1)) {
kerr << "Vector out of bounds caught!" << Kt::newline; kerr << "Vector out of bounds caught!" << Kt::newline;
return T{}; return T{};
} }
@@ -41,17 +41,13 @@ namespace kcp
} }
void push_back(T value) { void push_back(T value) {
array = (T *)Memory::g_allocator->Realloc(array, sz + 1); array = (T *)Memory::g_allocator->Realloc(array, sizeof(T) * (sz + 1));
array[sz++] = value; array[sz++] = value;
} }
void test() { T* get_array()
array = (T *)Memory::g_allocator->Realloc(array, sz + 1);
}
T& get_array()
{ {
return *array; return array;
} }
}; };
}; };