diff --git a/include/util/deferred.hpp b/include/util/deferred.hpp index 479c2b9..aad7193 100644 --- a/include/util/deferred.hpp +++ b/include/util/deferred.hpp @@ -79,7 +79,7 @@ namespace util{ constexpr deferred::deferred(FArgs&&... args): m_args{std::forward(args)...}{} template - constexpr auto deferred::value(void) -> deferred::value_type{ + constexpr auto deferred::value(void) -> value_type{ return get_value_(std::make_index_sequence()); } template @@ -88,7 +88,7 @@ namespace util{ } template template - constexpr auto deferred::get_value_(std::index_sequence) -> deferred::value_type{ + constexpr auto deferred::get_value_(std::index_sequence) -> value_type{ return T{std::get(m_args)...}; } diff --git a/makefile b/makefile index 4783a71..e74ad31 100644 --- a/makefile +++ b/makefile @@ -130,7 +130,7 @@ else ifeq ($(MEMCHK),1) #use asan to check memory leaks/invalid accesses LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls - COMPILER_FLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls + COMPILER_FLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -DOUR_DICK_DISABLE_NOTHROW_ALLOCATE endif ifeq ($(UNDEFCHK),1) LDFLAGS+=-fsanitize=undefined diff --git a/src/engine/stb_alloc.cpp b/src/engine/stb_alloc.cpp index 7867435..551140c 100644 --- a/src/engine/stb_alloc.cpp +++ b/src/engine/stb_alloc.cpp @@ -1,6 +1,6 @@ /** This file is a part of our_dick - Copyright (C) 2020 rexy712 + Copyright (C) 2020-2022 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -31,7 +31,11 @@ extern "C"{ } void* our_dick_stb_realloc(void* data, size_t olds, size_t news){ void* newdata = our_dick_stb_malloc(news); - memcpy(newdata, data, olds); + if(!newdata) + return nullptr; + if(data) + memcpy(newdata, data, olds); + our_dick_stb_free(data); return newdata; } } diff --git a/src/nothrow_allocation.cpp b/src/nothrow_allocation.cpp index c835b61..936dfd6 100644 --- a/src/nothrow_allocation.cpp +++ b/src/nothrow_allocation.cpp @@ -1,6 +1,6 @@ /** This file is a part of our_dick - Copyright (C) 2020 rexy712 + Copyright (C) 2020-2022 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -20,6 +20,7 @@ #include //malloc, free #include +#ifndef OUR_DICK_DISABLE_NOTHROW_ALLOCATE void* operator new(size_t newsize){ return std::malloc(newsize); } @@ -37,3 +38,4 @@ void operator delete(void* ptr, std::align_val_t al)noexcept{ void operator delete(void* ptr, size_t)noexcept{ ::operator delete(ptr); } +#endif