Skip to content

Commit

Permalink
Fix build warnings (found with gcc -Wall)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhochsteger committed Dec 3, 2024
1 parent 0c1943c commit 3bfa6c1
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 65 deletions.
3 changes: 3 additions & 0 deletions libsrc/core/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ namespace ngcore
NETGEN_INLINE void NothingToDelete ()
{
mem_to_delete = nullptr;

// this memory is not managed by the Array anymore, so set the memory usage to 0
mt.Free(sizeof(T)*allocsize);
}

/// Change logical size. If necessary, do reallocation. Keeps contents.
Expand Down
2 changes: 1 addition & 1 deletion libsrc/csg/csgeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ namespace netgen
PrintMessage (2, "Object ", i, " has ", tams->GetNT(), " triangles");
}
}
catch (exception)
catch (const std::exception &)
{
cerr << "*************************************************************" << endl
<< "**** out of memory problem in CSG visualization ****" << endl
Expand Down
2 changes: 1 addition & 1 deletion libsrc/general/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace netgen
{
void * p = new char [(line.maxsize+5) * elsize];

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

Expand Down
2 changes: 1 addition & 1 deletion libsrc/interface/nginterface_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ namespace netgen
build_searchtree);
return ind - 1;
}
catch(NgException e) // quads not implemented curved yet
catch(const NgException & e) // quads not implemented curved yet
{
for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
{
Expand Down
4 changes: 2 additions & 2 deletions libsrc/interface/readuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ namespace netgen
in >> name;
cout << IM(3) << len << " element are in group " << name << endl;
int hi, index;
int fdnr, ednr;
int fdnr=-1, ednr=-1;

in >> hi >> index >> hi >> hi;
int codim = get<1>(element_map[index]);
Expand Down Expand Up @@ -712,7 +712,7 @@ namespace netgen
if(!UserFormatRegister::HaveFormat(format))
throw Exception("Unknown format: " + format);

const auto & entry = UserFormatRegister::Get(format);
const auto entry = UserFormatRegister::Get(format);
if(!entry.read)
throw Exception("Reading format " + format + " is not implemented");

Expand Down
26 changes: 13 additions & 13 deletions libsrc/interface/rw_medit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<
for([[maybe_unused]] auto k : Range(nvert)) {
for(auto i : Range(dim))
fin >> p[i];
fin >> index;
mesh.AddPoint(p);
fin >> index;
mesh.AddPoint(p);
}
}
else if(token == "Edges") {
Expand All @@ -64,10 +64,10 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<
for([[maybe_unused]] auto k : Range(nedge)) {
for(auto i : Range(2))
fin >> seg[i];
fin >> seg.edgenr;
seg.edgenr = getIndex(1, seg.edgenr);
seg.si = seg.edgenr;
mesh.AddSegment(seg);
fin >> seg.edgenr;
seg.edgenr = getIndex(1, seg.edgenr);
seg.si = seg.edgenr;
mesh.AddSegment(seg);
}
}
else if(token == "Triangles") {
Expand All @@ -77,9 +77,9 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<
for([[maybe_unused]] auto k : Range(ntrig)) {
for(auto i : Range(3))
fin >> sel[i];
fin >> index;
sel.SetIndex(getIndex(2, index));
mesh.AddSurfaceElement(sel);
fin >> index;
sel.SetIndex(getIndex(2, index));
mesh.AddSurfaceElement(sel);
}
}
else if(token == "Tetrahedra") {
Expand All @@ -89,10 +89,10 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<
for([[maybe_unused]] auto k : Range(ntet)) {
for(auto i : Range(4))
fin >> el[i];
fin >> index;
el.SetIndex(getIndex(3, index));
el.Invert();
mesh.AddVolumeElement(el);
fin >> index;
el.SetIndex(getIndex(3, index));
el.Invert();
mesh.AddVolumeElement(el);
}
}
else if(token == "Corners") {
Expand Down
2 changes: 1 addition & 1 deletion libsrc/interface/writeuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool WriteUserFormat (const string & format,
if(!UserFormatRegister::HaveFormat(format))
return true;

const auto & entry = UserFormatRegister::Get(format);
const auto entry = UserFormatRegister::Get(format);
if(!entry.write)
return true;

Expand Down
4 changes: 2 additions & 2 deletions libsrc/linalg/densemat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace netgen
{
data = NULL; height = width = 0;
SetSize (m2.Height(), m2.Width());
if (Height()*Width())
if (Height() && Width())
memcpy (data, m2.data, sizeof(double) * (Height() * Width()));
}

Expand All @@ -70,7 +70,7 @@ namespace netgen

delete[] data;

if (h*w)
if (h && w)
data = new double[h*w];
else
data = NULL;
Expand Down
6 changes: 3 additions & 3 deletions libsrc/meshing/boundarylayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,9 +788,9 @@ namespace netgen
if(fabs(mat.Det()) > 1e-6)
break;
}
int maxpos1;
int maxpos2;
double val = 0;
int maxpos1 = 0;
int maxpos2 = 1;
double val = ns[0] * ns[1];
for (auto i : Range(ns))
{
for (auto j : Range(i + 1, ns.Size()))
Expand Down
5 changes: 3 additions & 2 deletions libsrc/meshing/improve3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,8 @@ double MeshOptimize3d :: SwapImproveEdge (
bad3 += GetLegalPenalty();
}

bool swap2, swap3;
bool swap2=false;
bool swap3=false;

if (goal == OPT_CONFORM)
{
Expand Down Expand Up @@ -2608,7 +2609,7 @@ double MeshOptimize3d :: SplitImprove2Element (
// search for very flat tets, with two disjoint edges nearly crossing, like a rectangle with diagonals
int minedge = -1;
double mindist = 1e99;
double minlam0, minlam1;
double minlam0=0, minlam1=0;

for (int i : Range(3))
{
Expand Down
4 changes: 2 additions & 2 deletions libsrc/meshing/meshclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ namespace netgen
auto& el = mesh.SurfaceElement(velement);
if(el.GetType() == TRIG)
{
double seg_lam;
double lam;
double seg_lam=-1;
double lam=-1;
auto seg = mesh.LineSegment(segs[i]);
for(auto k : Range(3))
{
Expand Down
48 changes: 23 additions & 25 deletions libsrc/meshing/meshfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ namespace netgen
for (int i = 1; i <= mesh.GetNOpenElements(); i++)
md.meshing->AddBoundaryElement (mesh.OpenElement(i));

if (mp.delaunay && mesh.GetNOpenElements())
{
if (mp.delaunay && mesh.GetNOpenElements())
{
int oldne = mesh.GetNE();

md.meshing->Delaunay (mesh, domain, mp);
Expand All @@ -408,22 +408,22 @@ namespace netgen
PrintMessage (3, mesh.GetNP(), " points, ",
mesh.GetNE(), " elements");
mesh.FindOpenElements(domain);
}
}

Box<3> domain_bbox( Box<3>::EMPTY_BOX );
Box<3> domain_bbox( Box<3>::EMPTY_BOX );

for (auto & sel : mesh.SurfaceElements())
for (auto & sel : mesh.SurfaceElements())
{
if (sel.IsDeleted() ) continue;

for (auto pi : sel.PNums())
domain_bbox.Add (mesh[pi]);
}
domain_bbox.Increase (0.01 * domain_bbox.Diam());
domain_bbox.Increase (0.01 * domain_bbox.Diam());

int cntsteps = 0;
int meshed;
if (mesh.GetNOpenElements())
int cntsteps = 0;
int meshed;
if (mesh.GetNOpenElements())
do
{
if (multithread.terminate)
Expand Down Expand Up @@ -515,24 +515,22 @@ namespace netgen
PrintMessage (1, "Success !");
}
}
while (!meshed);

{
PrintMessage (3, "Check subdomain ", domain, " / ", mesh.GetNDomains());
while (!meshed);

mesh.FindOpenElements(domain);
PrintMessage (3, "Check subdomain ", domain, " / ", mesh.GetNDomains());

bool res = (mesh.CheckConsistentBoundary() != 0);
if (res)
{
if(debugparam.write_mesh_on_error)
md.mesh->Save("inconsistent_surface_domain_"+ToString(md.domain)+".vol.gz");
PrintError ("Surface mesh not consistent");
throw NgException ("Stop meshing since surface mesh not consistent");
}
}
RemoveIllegalElements (mesh, domain);
ConformToFreeSegments (mesh, domain);
mesh.FindOpenElements(domain);

bool res = (mesh.CheckConsistentBoundary() != 0);
if (res)
{
if(debugparam.write_mesh_on_error)
md.mesh->Save("inconsistent_surface_domain_"+ToString(md.domain)+".vol.gz");
PrintError ("Surface mesh not consistent");
throw NgException ("Stop meshing since surface mesh not consistent");
}
RemoveIllegalElements (mesh, domain);
ConformToFreeSegments (mesh, domain);
}

void MergeMeshes( Mesh & mesh, Array<MeshingData> & md )
Expand Down
3 changes: 2 additions & 1 deletion libsrc/meshing/meshtype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ namespace netgen
}
constexpr PointIndex (t_invalid inv) : i(PointIndex::BASE-1) { ; }
// PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; }
constexpr operator int () const { return i; }
constexpr operator const int& () const { return i; }
explicit constexpr operator int& () { return i; }
PointIndex operator++ (int) { PointIndex hi(*this); i++; return hi; }
PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; }
PointIndex & operator++ () { i++; return *this; }
Expand Down
2 changes: 1 addition & 1 deletion libsrc/meshing/python_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
.def(py::init<int>())
.def("__repr__", &ToString<PointIndex>)
.def("__str__", &ToString<PointIndex>)
.def_property_readonly("nr", &PointIndex::operator int)
.def_property_readonly("nr", &PointIndex::operator const int&)
.def("__eq__" , FunctionPointer( [](PointIndex &self, PointIndex &other)
{ return static_cast<int>(self)==static_cast<int>(other); }) )
.def("__hash__" , FunctionPointer( [](PointIndex &self ) { return static_cast<int>(self); }) )
Expand Down
2 changes: 1 addition & 1 deletion libsrc/stlgeom/python_stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ NGCORE_API_EXPORT void ExportSTL(py::module & m)
.def("GetVicinity", [] (shared_ptr<STLGeometry> self, int node, int size, string type) {
NgArray<int> vic;

int trig;
int trig=-1;
if(type == "trig")
trig = node;

Expand Down
4 changes: 2 additions & 2 deletions libsrc/visualization/vsmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ namespace netgen


}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
// cout << "don't have a mesh to visualize" << endl;
VisualScene::DrawScene();
Expand Down Expand Up @@ -895,7 +895,7 @@ namespace netgen

vstimestamp = meshtimestamp;
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
PrintMessage (3, "vsmesh::buildscene: don't have a mesh to visualize");
VisualScene::BuildScene (zoomall);
Expand Down
4 changes: 2 additions & 2 deletions libsrc/visualization/vssolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ namespace netgen
// delete lock;
// mem_lock.UnLock();
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
// cout << "don't have a mesh to visualize" << endl;
VisualScene::DrawScene();
Expand Down Expand Up @@ -1120,7 +1120,7 @@ namespace netgen

clipplanetimestamp = max2 (vispar.clipping.timestamp, solutiontimestamp);
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
PrintMessage (3, "vssolution::buildscene: don't have a mesh to visualize");
VisualScene::BuildScene (zoomall);
Expand Down
10 changes: 5 additions & 5 deletions ng/ngpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace netgen
if(mesh->GetGeometry())
ng_geometry = mesh->GetGeometry();
}
catch (NgException e)
catch (const NgException & e)
{
PrintMessage (3, e.What());
return TCL_ERROR;
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace netgen
geometry -> LoadSurfaces(infile);
}
}
catch (NgException e)
catch (const NgException & e)
{
PrintMessage (3, e.What());
return TCL_ERROR;
Expand Down Expand Up @@ -551,7 +551,7 @@ namespace netgen
}
}

catch (NgException e)
catch (const NgException & e)
{
Tcl_SetResult (interp, const_cast<char*> (e.What().c_str()), TCL_VOLATILE);
return TCL_ERROR;
Expand Down Expand Up @@ -582,7 +582,7 @@ namespace netgen
{
ng_geometry -> Save (string (cfilename));
}
catch (NgException e)
catch (const NgException & e)
{
Tcl_SetResult (interp, const_cast<char*> (e.What().c_str()), TCL_VOLATILE);
return TCL_ERROR;
Expand Down Expand Up @@ -1440,7 +1440,7 @@ namespace netgen
PrintMessage (1, "Meshing done, time = ", GetTime(), " sec");
}

catch (NgException e)
catch (const NgException & e)
{
cout << e.What() << endl;
}
Expand Down

0 comments on commit 3bfa6c1

Please sign in to comment.