summaryrefslogtreecommitdiff
path: root/asl
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-12-29 23:38:15 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-12-29 23:38:15 +0100
commit38d024c6f3d55f1ffbb1597c563ad0ee1625b09f (patch)
tree1b46ccafc2dd92f8f23bab6b9a2cfb3a4fac2be9 /asl
parent6c035e411328c5f4c523125ad692a6e9afdb0636 (diff)
Fix use of aligned_alloc on Linux
Diffstat (limited to 'asl')
-rw-r--r--asl/allocator.cpp4
-rw-r--r--asl/buffer.hpp1
-rw-r--r--asl/tests/format_tests.cpp14
3 files changed, 14 insertions, 5 deletions
diff --git a/asl/allocator.cpp b/asl/allocator.cpp
index 645dd22..5dbdce0 100644
--- a/asl/allocator.cpp
+++ b/asl/allocator.cpp
@@ -18,8 +18,8 @@ void* asl::GlobalHeap::alloc(const layout& layout)
static_cast<size_t>(layout.align));
#elif ASL_OS_LINUX
void* ptr = ::aligned_alloc(
- static_cast<size_t>(layout.size),
- static_cast<size_t>(layout.align));
+ static_cast<size_t>(layout.align),
+ static_cast<size_t>(layout.size));
#endif
ASL_ASSERT(ptr != nullptr); // @Todo panic
return ptr;
diff --git a/asl/buffer.hpp b/asl/buffer.hpp
index 74465bd..12cbb80 100644
--- a/asl/buffer.hpp
+++ b/asl/buffer.hpp
@@ -117,6 +117,7 @@ public:
// @Todo Destructor
// @Todo clear
// @Todo Copy/move constructor & assignment
+ // @Todo Do leak checks on Linux
constexpr isize_t size() const
{
diff --git a/asl/tests/format_tests.cpp b/asl/tests/format_tests.cpp
index 906fce6..042fcb4 100644
--- a/asl/tests/format_tests.cpp
+++ b/asl/tests/format_tests.cpp
@@ -12,6 +12,11 @@ class StringSink : public asl::Writer
char* m_data{};
public:
+ ~StringSink()
+ {
+ reset();
+ }
+
void write(asl::span<const asl::byte> str) override
{
m_data = reinterpret_cast<char*>(asl::GlobalHeap::realloc(
@@ -28,9 +33,12 @@ public:
void reset()
{
- m_current_len = 0;
- asl::GlobalHeap::dealloc(m_data, asl::layout::array<char>(m_current_len));
- m_data = nullptr;
+ if (m_data != nullptr)
+ {
+ m_current_len = 0;
+ asl::GlobalHeap::dealloc(m_data, asl::layout::array<char>(m_current_len));
+ m_data = nullptr;
+ }
}
};