From ae87c7005c85aad90874fa9991d330a547565e91 Mon Sep 17 00:00:00 2001 From: Monty Montgomery Date: Sun, 15 May 2022 00:39:44 -0400 Subject: [PATCH] Two nullptr deref fixes in table Don't delete memory that wasn't allocated. Similarly, we can't deref the first element of an array that was never allocated. --- libsrc/general/table.cpp | 10 ++++++---- libsrc/general/table.hpp | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libsrc/general/table.cpp b/libsrc/general/table.cpp index 732d63c3..e39d671b 100644 --- a/libsrc/general/table.cpp +++ b/libsrc/general/table.cpp @@ -108,14 +108,16 @@ namespace netgen if (line.size == line.maxsize) { void * p = new char [(line.maxsize+5) * elsize]; - - memcpy (p, line.col, line.maxsize * elsize); - delete [] (char*)line.col; + + if (line.size > 0 && line.col != NULL) { + memcpy (p, line.col, line.maxsize * elsize); + delete [] (char*)line.col; + } line.col = p; line.maxsize += 5; } - + line.size++; } diff --git a/libsrc/general/table.hpp b/libsrc/general/table.hpp index 535d0212..44c5f9fb 100644 --- a/libsrc/general/table.hpp +++ b/libsrc/general/table.hpp @@ -120,7 +120,8 @@ public: /// Creates fixed maximal element size table inline TABLE (const NgFlatArray & entrysizes) - : BASE_TABLE (NgFlatArray (entrysizes.Size(), const_cast(&entrysizes[BASE])), + : BASE_TABLE (NgFlatArray (entrysizes.Size(), + entrysizes.Size() > 0 ? const_cast(&entrysizes[BASE]) : 0), sizeof(T)) { ; }