Skip to content

Commit

Permalink
Fix possible memory error.
Browse files Browse the repository at this point in the history
If all tetra (resp. points) are deleted, the last deletion (iel == mesh->ne)
 leads to mesh->ne = -1 (resp. mesh->np = -1) and to a memory error
 if we don't add a security guard.

See for example the `mmg3d_hybrid-nsd1` continuous integration test with
PATTERN and SCOTCH options setted to off.
  • Loading branch information
Algiane committed Dec 5, 2023
1 parent bdbf11a commit 79331dc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mmg3d/zaldy_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void MMG3D_delPt(MMG5_pMesh mesh,MMG5_int ip) {
ppt->tmp = mesh->npnil;
mesh->npnil = ip;
if ( ip == mesh->np ) {
while ( !MG_VOK((&mesh->point[mesh->np])) ) mesh->np--;
while ( (!MG_VOK((&mesh->point[mesh->np]))) && mesh->np ) mesh->np--;
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ int MMG3D_delElt(MMG5_pMesh mesh,MMG5_int iel) {
memset(&mesh->adja[iadr],0,4*sizeof(MMG5_int));
mesh->nenil = iel;
if ( iel == mesh->ne ) {
while ( !MG_EOK((&mesh->tetra[mesh->ne])) ) mesh->ne--;
while ( (!MG_EOK((&mesh->tetra[mesh->ne]))) && mesh->ne ) mesh->ne--;
}
return 1;
}
Expand Down

0 comments on commit 79331dc

Please sign in to comment.