Skip to content

Commit

Permalink
Fix issue with initialization to INT_MAX when Mmg is built with int64…
Browse files Browse the repository at this point in the history
…_t integers.
  • Loading branch information
Algiane committed Sep 12, 2023
1 parent 9c69a7c commit de3046f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/common/mmg2.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,13 @@ int MMG5_MultiMat_init(MMG5_pMesh mesh) {

/* Initialize the max and min reference */
refmax = 0;
refmin = INT_MAX;

if ( sizeof(MMG5_int) == 8 ) {
refmin = LONG_MAX;
}
else {
refmin = INT_MAX;
}

/* Look for the max/min reference provided in material table */
for( k = 0; k < mesh->info.nmat; k++ ) {
Expand Down
10 changes: 9 additions & 1 deletion src/mmg2d/API_functions_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,17 @@ int MMG2D_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int va
return 0);
MMG5_SAFE_CALLOC(mesh->info.par,mesh->info.npar,MMG5_Par,return 0);

MMG5_int inival;
if ( sizeof(MMG5_int) == 8 ) {
inival = LONG_MAX;
}
else {
inival = INT_MAX;
}

for (k=0; k<mesh->info.npar; k++) {
mesh->info.par[k].elt = MMG5_Noentity;
mesh->info.par[k].ref = INT_MAX;
mesh->info.par[k].ref = inival;
mesh->info.par[k].hausd = mesh->info.hausd;
mesh->info.par[k].hmin = mesh->info.hmin;
mesh->info.par[k].hmax = mesh->info.hmax;
Expand Down
17 changes: 15 additions & 2 deletions src/mmg2d/hash_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ int MMG2D_hashTria(MMG5_pMesh mesh) {
hsize = mesh->nt;

/* init */
inival = INT_MAX;
if ( sizeof(MMG5_int) == 8 ) {
inival = LONG_MAX;
}
else {
inival = INT_MAX;
}

for (k=0; k<=mesh->nt; k++)
hcode[k] = -inival;

Expand Down Expand Up @@ -185,7 +191,14 @@ int MMG2D_hashQuad(MMG5_pMesh mesh) {

/* init */
if ( mesh->info.ddebug ) fprintf(stdout," h- stage 1: init\n");
inival = INT_MAX;

if ( sizeof(MMG5_int) == 8 ) {
inival = LONG_MAX;
}
else {
inival = INT_MAX;
}

iadr = 0;
for (k=0; k<=mesh->nquad; k++)
hcode[k] = -inival;
Expand Down
10 changes: 9 additions & 1 deletion src/mmg3d/API_functions_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -2230,9 +2230,17 @@ int MMG3D_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam,MMG5_int val
return 0);
MMG5_SAFE_CALLOC(mesh->info.par,mesh->info.npar,MMG5_Par,return 0);

MMG5_int inival;
if ( sizeof(MMG5_int) == 8 ) {
inival = LONG_MAX;
}
else {
inival = INT_MAX;
}

for (k=0; k<mesh->info.npar; k++) {
mesh->info.par[k].elt = MMG5_Noentity;
mesh->info.par[k].ref = INT_MAX;
mesh->info.par[k].ref = inival;
mesh->info.par[k].hausd = mesh->info.hausd;
mesh->info.par[k].hmin = mesh->info.hmin;
mesh->info.par[k].hmax = mesh->info.hmax;
Expand Down
18 changes: 16 additions & 2 deletions src/mmg3d/hash_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ int MMG3D_hashTetra(MMG5_pMesh mesh, int pack) {

/* init */
if ( mesh->info.ddebug ) fprintf(stdout," h- stage 1: init\n");
inival = INT_MAX;

if ( sizeof(MMG5_int) == 8 ) {
inival = LONG_MAX;
}
else {
inival = INT_MAX;
}

iadr = 0;
for (k=0; k<=mesh->ne; k++)
hcode[k] = -inival;
Expand Down Expand Up @@ -270,7 +277,14 @@ int MMG3D_hashPrism(MMG5_pMesh mesh) {

/* init */
if ( mesh->info.ddebug ) fprintf(stdout," h- stage 1: init\n");
inival = INT_MAX;

if ( sizeof(MMG5_int) == 8 ) {
inival = LONG_MAX;
}
else {
inival = INT_MAX;
}

iadr = 0;
for (k=0; k<=mesh->nprism; k++)
hcode[k] = -inival;
Expand Down
10 changes: 9 additions & 1 deletion src/mmgs/API_functions_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,9 +1389,17 @@ int MMGS_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int val
return 0);
MMG5_SAFE_CALLOC(mesh->info.par,mesh->info.npar,MMG5_Par,return 0);

MMG5_int inival;
if ( sizeof(MMG5_int) == 8 ) {
inival = LONG_MAX;
}
else {
inival = INT_MAX;
}

for (k=0; k<mesh->info.npar; k++) {
mesh->info.par[k].elt = MMG5_Noentity;
mesh->info.par[k].ref = INT_MAX;
mesh->info.par[k].ref = inival;
mesh->info.par[k].hausd = mesh->info.hausd;
mesh->info.par[k].hmin = mesh->info.hmin;
mesh->info.par[k].hmax = mesh->info.hmax;
Expand Down

3 comments on commit de3046f

@prj-
Copy link
Contributor

@prj- prj- commented on de3046f Sep 17, 2023

Choose a reason for hiding this comment

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

Please keep the develop branch in sync.

@Algiane
Copy link
Member Author

Choose a reason for hiding this comment

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

It is done,
Sorry

@prj-
Copy link
Contributor

@prj- prj- commented on de3046f Sep 18, 2023

Choose a reason for hiding this comment

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

No worries, thank you.

Please sign in to comment.