diff --git a/.gitignore b/.gitignore index fc831d1d..f3f6dba6 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ CMakeFiles/ CMakeDoxyfile.in install_manifest.txt Testing/ -build/ +build*/ # msvc / Windows *.vcxproj* diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ba56ace..d26a18c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,6 @@ list(APPEND CMAKE_PREFIX_PATH "${LIBLCF_PREFIX_PATH_APPEND}") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) - # lcf library files set(LCF_SOURCES src/dbarray.cpp diff --git a/src/dbarray.cpp b/src/dbarray.cpp index b10f4ba6..4edd91c8 100644 --- a/src/dbarray.cpp +++ b/src/dbarray.cpp @@ -12,8 +12,6 @@ namespace lcf { -const DBArrayAlloc::size_type DBArrayAlloc::_empty_buf[2] = { 0, 0 }; - static ptrdiff_t HeaderSize(size_t align) { return std::max(sizeof(DBArrayAlloc::size_type), align); } @@ -48,8 +46,9 @@ void* DBArrayAlloc::alloc(size_type size, size_type field_size, size_type align) void DBArrayAlloc::free(void* p, size_type align) noexcept { assert(p != nullptr); - if (p != empty_buf()) { - auto* raw = Adjust(p, -HeaderSize(align)); + if (*get_size_ptr(p)!=0) { + void* raw = new void*; + raw = Adjust(p, -HeaderSize(align)); #ifdef LCF_DEBUG_DBARRAY std::cout << "DBArray: Free" << " align=" << align @@ -58,7 +57,9 @@ void DBArrayAlloc::free(void* p, size_type align) noexcept { << " field_size=" << *get_size_ptr(p) << std::endl; #endif - ::operator delete(raw); + delete(raw); + + } } @@ -71,7 +72,7 @@ char* DBString::construct_z(const char* s, size_t len) { } char* DBString::construct_sv(const char* s, size_t len) { - auto* p = alloc(len); + char* p = alloc(len); if (len) { std::memcpy(p, s, len); p[len] = '\0'; @@ -80,6 +81,7 @@ char* DBString::construct_sv(const char* s, size_t len) { } DBString& DBString::operator=(const DBString& o) { + if (this != &o) { destroy(); _storage = construct_z(o.data(), o.size()); diff --git a/src/lcf/dbarrayalloc.h b/src/lcf/dbarrayalloc.h index 740c3c2b..edfc1faa 100644 --- a/src/lcf/dbarrayalloc.h +++ b/src/lcf/dbarrayalloc.h @@ -27,9 +27,9 @@ struct DBArrayAlloc { static void free(void* p, size_type align) noexcept; static void* empty_buf() { - return const_cast(&_empty_buf[1]); - } + return (void*)(&_empty_buf + 1); + } static constexpr size_type* get_size_ptr(void* p) { return static_cast(p) - 1; } @@ -39,7 +39,7 @@ struct DBArrayAlloc { } private: - static const size_type _empty_buf[2]; + static const uint16_t _empty_buf = 0; }; } // namespace lcf