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.
This commit is contained in:
Monty Montgomery 2022-05-15 00:39:44 -04:00
parent 6ba4a6e6c6
commit ae87c7005c
2 changed files with 8 additions and 5 deletions

View File

@ -108,14 +108,16 @@ namespace netgen
if (line.size == line.maxsize) if (line.size == line.maxsize)
{ {
void * p = new char [(line.maxsize+5) * elsize]; void * p = new char [(line.maxsize+5) * elsize];
memcpy (p, line.col, line.maxsize * elsize); if (line.size > 0 && line.col != NULL) {
delete [] (char*)line.col; memcpy (p, line.col, line.maxsize * elsize);
delete [] (char*)line.col;
}
line.col = p; line.col = p;
line.maxsize += 5; line.maxsize += 5;
} }
line.size++; line.size++;
} }

View File

@ -120,7 +120,8 @@ public:
/// Creates fixed maximal element size table /// Creates fixed maximal element size table
inline TABLE (const NgFlatArray<int,BASE> & entrysizes) inline TABLE (const NgFlatArray<int,BASE> & entrysizes)
: BASE_TABLE (NgFlatArray<int> (entrysizes.Size(), const_cast<int*>(&entrysizes[BASE])), : BASE_TABLE (NgFlatArray<int> (entrysizes.Size(),
entrysizes.Size() > 0 ? const_cast<int*>(&entrysizes[BASE]) : 0),
sizeof(T)) sizeof(T))
{ ; } { ; }