check for num=0 before memcpy

This commit is contained in:
Joachim Schoeberl 2024-11-25 17:25:40 +01:00
parent 22797971f6
commit a86d231714
2 changed files with 5 additions and 3 deletions

View File

@ -108,8 +108,9 @@ 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.maxsize*elsize)
memcpy (p, line.col, line.maxsize * elsize);
delete [] (char*)line.col; delete [] (char*)line.col;
line.col = p; line.col = p;

View File

@ -49,7 +49,8 @@ namespace netgen
{ {
data = NULL; height = width = 0; data = NULL; height = width = 0;
SetSize (m2.Height(), m2.Width()); SetSize (m2.Height(), m2.Width());
memcpy (data, m2.data, sizeof(double) * Height() * Width()); if (Height()*Width())
memcpy (data, m2.data, sizeof(double) * (Height() * Width()));
} }
DenseMatrix :: ~DenseMatrix () DenseMatrix :: ~DenseMatrix ()