From 90916feecc62932701e4f8ae367a20f1c77215a9 Mon Sep 17 00:00:00 2001 From: Algiane Froehly Date: Tue, 5 Dec 2023 15:03:52 +0100 Subject: [PATCH] Add checks to prilen functions. 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) --- src/mmg2d/length_2d.c | 6 ++++++ src/mmg3d/quality_3d.c | 10 ++++++++++ src/mmgs/quality_s.c | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/mmg2d/length_2d.c b/src/mmg2d/length_2d.c index 3f6168baa..fbcfd004b 100644 --- a/src/mmg2d/length_2d.c +++ b/src/mmg2d/length_2d.c @@ -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; } diff --git a/src/mmg3d/quality_3d.c b/src/mmg3d/quality_3d.c index 98724323d..ba82544d6 100644 --- a/src/mmg3d/quality_3d.c +++ b/src/mmg3d/quality_3d.c @@ -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; diff --git a/src/mmgs/quality_s.c b/src/mmgs/quality_s.c index 3df84b8ac..7d5fba89b 100644 --- a/src/mmgs/quality_s.c +++ b/src/mmgs/quality_s.c @@ -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;