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.
This commit is contained in:
parent
5f72e9c763
commit
e13a4d6539
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue