Skip to content

Commit

Permalink
Add checks to prilen functions.
Browse files Browse the repository at this point in the history
Add to prilen funcs:
  - the check that the metric is allocated (avoid memory errors in ParMmg when calling computePrilen)
  - the check that the element array is not empty (avoid infinite edge lengths when mesh->nt = 0, for example after domain deletion)
  • Loading branch information
Algiane committed Dec 5, 2023
1 parent dd7dab0 commit 90916fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/mmg2d/length_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ int MMG2D_prilen(MMG5_pMesh mesh,MMG5_pSol sol) {
ibmax = 0;
nullEdge = 0;

if ( (!sol) || (!sol->m) ) {
/* the functions that computes the edge length cannot be called without an
* allocated metric */
return 0;
}

if ( !mesh->nt ) {
return 0;
}
Expand Down
10 changes: 10 additions & 0 deletions src/mmg3d/quality_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ int MMG3D_computePrilen( MMG5_pMesh mesh, MMG5_pSol met, double* avlen,
*amin = *amax = *bmin = *bmax = 0;
*nullEdge = 0;

if ( (!met) || (!met->m) ) {
/* the functions that computes the edge length cannot be called without an
* allocated metric */
return 0;
}

if ( !mesh->ne ) {
return 0;
}

/* Hash all edges in the mesh */
if ( !MMG5_hashNew(mesh,&hash,mesh->np,7*mesh->np) ) return 0;

Expand Down
10 changes: 10 additions & 0 deletions src/mmgs/quality_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ int MMGS_prilen(MMG5_pMesh mesh, MMG5_pSol met, int metRidTyp) {
amin = amax = bmin = bmax = 0;
nullEdge = 0;

if ( (!met) || (!met->m) ) {
/* the functions that computes the edge length cannot be called without an
* allocated metric */
return 0;
}

if ( !mesh->nt ) {
return 0;
}

/* Hash all edges in the mesh */
if ( !MMG5_hashNew(mesh,&hash,mesh->np,7*mesh->np) ) return 0;

Expand Down

0 comments on commit 90916fe

Please sign in to comment.