From 104116517533c05671ebdbbfd566096fbae4c6af Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 6 Jun 2024 12:14:37 -0700 Subject: [PATCH 1/2] kp_space_time_stack.cpp: do nil check at de/alloc function kp_space_time_stack.cpp: do null pointer check of ptr at the beginning of alloc and dealloc functions --- profiling/space-time-stack/kp_space_time_stack.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/profiling/space-time-stack/kp_space_time_stack.cpp b/profiling/space-time-stack/kp_space_time_stack.cpp index 897ce9252..5c64d76ba 100644 --- a/profiling/space-time-stack/kp_space_time_stack.cpp +++ b/profiling/space-time-stack/kp_space_time_stack.cpp @@ -521,12 +521,14 @@ struct Allocations { Allocations() : total_size(0) {} void allocate(std::string&& name, const void* ptr, std::uint64_t size, StackNode* frame) { + if(ptr == nullptr) { assert(size==0); return; } auto res = alloc_set.emplace(Allocation(std::move(name), ptr, size, frame)); assert(res.second); total_size += size; } void deallocate(std::string&& name, const void* ptr, std::uint64_t size, StackNode* frame) { + if(ptr == nullptr) { assert(size==0); return; } auto key = Allocation(std::move(name), ptr, size, frame); auto it = alloc_set.find(key); if (it == alloc_set.end()) { From a8c9ca00ab78c70f11dfafd4e728c22f91232357 Mon Sep 17 00:00:00 2001 From: Vivek Kale Date: Thu, 6 Jun 2024 14:26:38 -0700 Subject: [PATCH 2/2] kp_space_time_stack.cpp: apply clang-format --- profiling/space-time-stack/kp_space_time_stack.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/profiling/space-time-stack/kp_space_time_stack.cpp b/profiling/space-time-stack/kp_space_time_stack.cpp index 5c64d76ba..a5cbfed8e 100644 --- a/profiling/space-time-stack/kp_space_time_stack.cpp +++ b/profiling/space-time-stack/kp_space_time_stack.cpp @@ -521,14 +521,20 @@ struct Allocations { Allocations() : total_size(0) {} void allocate(std::string&& name, const void* ptr, std::uint64_t size, StackNode* frame) { - if(ptr == nullptr) { assert(size==0); return; } + if (ptr == nullptr) { + assert(size == 0); + return; + } auto res = alloc_set.emplace(Allocation(std::move(name), ptr, size, frame)); assert(res.second); total_size += size; } void deallocate(std::string&& name, const void* ptr, std::uint64_t size, StackNode* frame) { - if(ptr == nullptr) { assert(size==0); return; } + if (ptr == nullptr) { + assert(size == 0); + return; + } auto key = Allocation(std::move(name), ptr, size, frame); auto it = alloc_set.find(key); if (it == alloc_set.end()) {