From 2c1262b436bff3cd7b9b81b21628f613116d7f6c Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 24 Aug 2022 16:33:05 +1000 Subject: [PATCH] ImVector: fix undefined behaviour during copy operator if source vector is null. (#5608) --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index eb3d8b640..155512e09 100644 --- a/imgui.h +++ b/imgui.h @@ -1765,7 +1765,7 @@ struct ImVector // Constructors, destructor inline ImVector() { Size = Capacity = 0; Data = NULL; } inline ImVector(const ImVector& src) { Size = Capacity = 0; Data = NULL; operator=(src); } - inline ImVector& operator=(const ImVector& src) { clear(); resize(src.Size); memcpy(Data, src.Data, (size_t)Size * sizeof(T)); return *this; } + inline ImVector& operator=(const ImVector& src) { clear(); resize(src.Size); if (src.Data) memcpy(Data, src.Data, (size_t)Size * sizeof(T)); return *this; } inline ~ImVector() { if (Data) IM_FREE(Data); } // Important: does not destruct anything inline void clear() { if (Data) { Size = Capacity = 0; IM_FREE(Data); Data = NULL; } } // Important: does not destruct anything