From e13a4d653984eaaa4d3a30fcb76df9a7d17f085c Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Mon, 3 Sep 2018 16:10:31 -0600 Subject: [PATCH] pstatclient: Never pass nullptr to memcpy Even though the only time this happened was when the size was 0, it's still undefined to pass memcpy a nullptr. --- panda/src/pstatclient/pStatClient.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index c69e1ea032..a0ddb2ae38 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -1056,7 +1056,9 @@ add_collector(PStatClient::Collector *collector) { // the lock. int new_collectors_size = (_collectors_size == 0) ? 128 : _collectors_size * 2; CollectorPointer *new_collectors = new CollectorPointer[new_collectors_size]; - memcpy(new_collectors, _collectors, _num_collectors * sizeof(CollectorPointer)); + if (_collectors != nullptr) { + memcpy(new_collectors, _collectors, _num_collectors * sizeof(CollectorPointer)); + } AtomicAdjust::set_ptr(_collectors, new_collectors); AtomicAdjust::set(_collectors_size, new_collectors_size); @@ -1091,7 +1093,9 @@ add_thread(PStatClient::InternalThread *thread) { // the lock. int new_threads_size = (_threads_size == 0) ? 128 : _threads_size * 2; ThreadPointer *new_threads = new ThreadPointer[new_threads_size]; - memcpy(new_threads, _threads, _num_threads * sizeof(ThreadPointer)); + if (_threads != nullptr) { + memcpy(new_threads, _threads, _num_threads * sizeof(ThreadPointer)); + } // We assume that assignment to a pointer and to an int are each atomic. AtomicAdjust::set_ptr(_threads, new_threads); AtomicAdjust::set(_threads_size, new_threads_size);