Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Patches for clean Fedora RPM builds that pass unit tests #123

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
10 changes: 6 additions & 4 deletions libsrc/general/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is incorrect.
Via SetSize2(row, 5); SetSize2(row, 0);, line.size becomes 0, but that does not mean the backing memory should not be freed.

Though, the allocation/deallocation is considerably flawed. The memory pointed to by line.col must only be freed when it does not point into oneblock. Unfortunately, that is not easy to check, as there is no end pointer.

memcpy (p, line.col, line.maxsize * elsize);
delete [] (char*)line.col;
}

line.col = p;
line.maxsize += 5;
}

line.size++;
}

Expand Down
3 changes: 2 additions & 1 deletion libsrc/general/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class TABLE : public BASE_TABLE

/// Creates fixed maximal element size table
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))
{ ; }

Expand Down