Skip to content

Commit 25935e1

Browse files
authored
Merge pull request Reference-ScaLAPACK#85 from gdonval/fix-malloc
Use `size_t` in `mr2d_malloc` instead of index-bound `Int`
2 parents 0234af9 + eaabe78 commit 25935e1

21 files changed

+84
-82
lines changed

REDIST/SRC/pcgemr.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ Cpcgemr2d(m, n,
342342
assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
343343
/* exchange the missing parameters among the processors: shape of grids and
344344
* location of the processors */
345-
param = (Int *) mr2d_malloc(3 * (nprocs * 2 + NBPARAM) * sizeof(Int));
345+
param = (Int *) mr2d_malloc(3 * ((size_t)nprocs * 2 + NBPARAM) * sizeof(Int));
346346
ra = param + nprocs * 2 + NBPARAM;
347347
ca = param + (nprocs * 2 + NBPARAM) * 2;
348348
for (i = 0; i < nprocs * 2 + NBPARAM; i++)
@@ -467,10 +467,10 @@ Cpcgemr2d(m, n,
467467
/* allocing room for the tabs, alloc for the worst case,local_n or local_m
468468
* intervals, in fact the worst case should be less, perhaps half that,I
469469
* should think of that one day. */
470-
h_inter = (IDESC *) mr2d_malloc(DIVUP(ma->n, q0 * ma->nbcol) *
471-
ma->nbcol * sizeof(IDESC));
472-
v_inter = (IDESC *) mr2d_malloc(DIVUP(ma->m, p0 * ma->nbrow)
473-
* ma->nbrow * sizeof(IDESC));
470+
h_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->n, q0 * ma->nbcol)) *
471+
(size_t)ma->nbcol * sizeof(IDESC));
472+
v_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->m, p0 * ma->nbrow))
473+
* (size_t)ma->nbrow * sizeof(IDESC));
474474
/* We go for the scanning of indices. For each processor including mypnum,
475475
* we fill the sendbuff buffer (scanD0(SENDBUFF)) and when it is done send
476476
* it. Then for each processor, we compute the size of message to be
@@ -570,7 +570,7 @@ init_chenille(Int mypnum, Int nprocs, Int n0, Int *proc0, Int n1, Int *proc1, In
570570
Int ns, nr, i, tot;
571571
Int *sender, *recver, *g0, *g1;
572572
tot = max(n0, n1);
573-
sender = (Int *) mr2d_malloc((nprocs + tot) * sizeof(Int) * 2);
573+
sender = (Int *) mr2d_malloc((size_t)(nprocs + tot) * sizeof(Int) * 2);
574574
recver = sender + tot;
575575
*psend = sender;
576576
*precv = recver;
@@ -706,7 +706,7 @@ gridreshape(Int *ctxtp)
706706
Int i, j;
707707
ori = *ctxtp;
708708
Cblacs_gridinfo(ori, &nprow, &npcol, &myrow, &mycol);
709-
usermap = mr2d_malloc(sizeof(Int) * nprow * npcol);
709+
usermap = mr2d_malloc(sizeof(Int) * (size_t)nprow * (size_t)npcol);
710710
for (i = 0; i < nprow; i++)
711711
for (j = 0; j < npcol; j++) {
712712
usermap[i + j * nprow] = Cblacs_pnum(ori, i, j);

REDIST/SRC/pcgemr2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ setmemory(complex **adpointer, Int blocksize)
121121
return;
122122
}
123123
*adpointer = (complex *) mr2d_malloc(
124-
blocksize * sizeof(complex));
124+
(size_t)blocksize * sizeof(complex));
125125
}
126126
/******************************************************************/
127127
/* Free the memory space after the malloc */

REDIST/SRC/pctrmr.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ Cpctrmr2d(uplo, diag, m, n,
359359
assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
360360
/* exchange the missing parameters among the processors: shape of grids and
361361
* location of the processors */
362-
param = (Int *) mr2d_malloc(3 * (nprocs * 2 + NBPARAM) * sizeof(Int));
362+
param = (Int *) mr2d_malloc(3 * ((size_t)nprocs * 2 + NBPARAM) * sizeof(Int));
363363
ra = param + nprocs * 2 + NBPARAM;
364364
ca = param + (nprocs * 2 + NBPARAM) * 2;
365365
for (i = 0; i < nprocs * 2 + NBPARAM; i++)
@@ -484,10 +484,10 @@ Cpctrmr2d(uplo, diag, m, n,
484484
/* allocing room for the tabs, alloc for the worst case,local_n or local_m
485485
* intervals, in fact the worst case should be less, perhaps half that,I
486486
* should think of that one day. */
487-
h_inter = (IDESC *) mr2d_malloc(DIVUP(ma->n, q0 * ma->nbcol) *
488-
ma->nbcol * sizeof(IDESC));
489-
v_inter = (IDESC *) mr2d_malloc(DIVUP(ma->m, p0 * ma->nbrow)
490-
* ma->nbrow * sizeof(IDESC));
487+
h_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->n, q0 * ma->nbcol)) *
488+
(size_t)ma->nbcol * sizeof(IDESC));
489+
v_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->m, p0 * ma->nbrow))
490+
* (size_t)ma->nbrow * sizeof(IDESC));
491491
/* We go for the scanning of indices. For each processor including mypnum,
492492
* we fill the sendbuff buffer (scanD0(SENDBUFF)) and when it is done send
493493
* it. Then for each processor, we compute the size of message to be
@@ -592,7 +592,7 @@ init_chenille(Int mypnum, Int nprocs, Int n0, Int *proc0, Int n1, Int *proc1, In
592592
Int ns, nr, i, tot;
593593
Int *sender, *recver, *g0, *g1;
594594
tot = max(n0, n1);
595-
sender = (Int *) mr2d_malloc((nprocs + tot) * sizeof(Int) * 2);
595+
sender = (Int *) mr2d_malloc((size_t)(nprocs + tot) * sizeof(Int) * 2);
596596
recver = sender + tot;
597597
*psend = sender;
598598
*precv = recver;
@@ -664,7 +664,7 @@ gridreshape(Int *ctxtp)
664664
Int i, j;
665665
ori = *ctxtp;
666666
Cblacs_gridinfo(ori, &nprow, &npcol, &myrow, &mycol);
667-
usermap = mr2d_malloc(sizeof(Int) * nprow * npcol);
667+
usermap = mr2d_malloc(sizeof(Int) * (size_t)nprow * (size_t)npcol);
668668
for (i = 0; i < nprow; i++)
669669
for (j = 0; j < npcol; j++) {
670670
usermap[i + j * nprow] = Cblacs_pnum(ori, i, j);

REDIST/SRC/pctrmr2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ setmemory(complex **adpointer, Int blocksize)
121121
return;
122122
}
123123
*adpointer = (complex *) mr2d_malloc(
124-
blocksize * sizeof(complex));
124+
(size_t)blocksize * sizeof(complex));
125125
}
126126
/******************************************************************/
127127
/* Free the memory space after the malloc */

REDIST/SRC/pdgemr.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Cpdgemr2d(m, n,
339339
assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
340340
/* exchange the missing parameters among the processors: shape of grids and
341341
* location of the processors */
342-
param = (Int *) mr2d_malloc(3 * (nprocs * 2 + NBPARAM) * sizeof(Int));
342+
param = (Int *) mr2d_malloc(3 * ((size_t)nprocs * 2 + NBPARAM) * sizeof(Int));
343343
ra = param + nprocs * 2 + NBPARAM;
344344
ca = param + (nprocs * 2 + NBPARAM) * 2;
345345
for (i = 0; i < nprocs * 2 + NBPARAM; i++)
@@ -464,10 +464,10 @@ Cpdgemr2d(m, n,
464464
/* allocing room for the tabs, alloc for the worst case,local_n or local_m
465465
* intervals, in fact the worst case should be less, perhaps half that,I
466466
* should think of that one day. */
467-
h_inter = (IDESC *) mr2d_malloc(DIVUP(ma->n, q0 * ma->nbcol) *
468-
ma->nbcol * sizeof(IDESC));
469-
v_inter = (IDESC *) mr2d_malloc(DIVUP(ma->m, p0 * ma->nbrow)
470-
* ma->nbrow * sizeof(IDESC));
467+
h_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->n, q0 * ma->nbcol)) *
468+
(size_t)ma->nbcol * sizeof(IDESC));
469+
v_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->m, p0 * ma->nbrow))
470+
* (size_t)ma->nbrow * sizeof(IDESC));
471471
/* We go for the scanning of indices. For each processor including mypnum,
472472
* we fill the sendbuff buffer (scanD0(SENDBUFF)) and when it is done send
473473
* it. Then for each processor, we compute the size of message to be
@@ -569,7 +569,7 @@ init_chenille(mypnum, nprocs, n0, proc0, n1, proc1, psend, precv, myrang)
569569
Int ns, nr, i, tot;
570570
Int *sender, *recver, *g0, *g1;
571571
tot = max(n0, n1);
572-
sender = (Int *) mr2d_malloc((nprocs + tot) * sizeof(Int) * 2);
572+
sender = (Int *) mr2d_malloc((size_t)(nprocs + tot) * sizeof(Int) * 2);
573573
recver = sender + tot;
574574
*psend = sender;
575575
*precv = recver;
@@ -713,7 +713,7 @@ gridreshape(Int *ctxtp)
713713
Int i, j;
714714
ori = *ctxtp;
715715
Cblacs_gridinfo(ori, &nprow, &npcol, &myrow, &mycol);
716-
usermap = mr2d_malloc(sizeof(Int) * nprow * npcol);
716+
usermap = mr2d_malloc(sizeof(Int) * (size_t)nprow * (size_t)npcol);
717717
for (i = 0; i < nprow; i++)
718718
for (j = 0; j < npcol; j++) {
719719
usermap[i + j * nprow] = Cblacs_pnum(ori, i, j);

REDIST/SRC/pdgemr2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ setmemory(double **adpointer, Int blocksize)
118118
return;
119119
}
120120
*adpointer = (double *) mr2d_malloc(
121-
blocksize * sizeof(double));
121+
(size_t)blocksize * sizeof(double));
122122
}
123123
/******************************************************************/
124124
/* Free the memory space after the malloc */

REDIST/SRC/pdtrmr.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Cpdtrmr2d(uplo, diag, m, n,
356356
assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
357357
/* exchange the missing parameters among the processors: shape of grids and
358358
* location of the processors */
359-
param = (Int *) mr2d_malloc(3 * (nprocs * 2 + NBPARAM) * sizeof(Int));
359+
param = (Int *) mr2d_malloc(3 * ((size_t)nprocs * 2 + NBPARAM) * sizeof(Int));
360360
ra = param + nprocs * 2 + NBPARAM;
361361
ca = param + (nprocs * 2 + NBPARAM) * 2;
362362
for (i = 0; i < nprocs * 2 + NBPARAM; i++)
@@ -481,10 +481,10 @@ Cpdtrmr2d(uplo, diag, m, n,
481481
/* allocing room for the tabs, alloc for the worst case,local_n or local_m
482482
* intervals, in fact the worst case should be less, perhaps half that,I
483483
* should think of that one day. */
484-
h_inter = (IDESC *) mr2d_malloc(DIVUP(ma->n, q0 * ma->nbcol) *
485-
ma->nbcol * sizeof(IDESC));
486-
v_inter = (IDESC *) mr2d_malloc(DIVUP(ma->m, p0 * ma->nbrow)
487-
* ma->nbrow * sizeof(IDESC));
484+
h_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->n, q0 * ma->nbcol)) *
485+
(size_t)ma->nbcol * sizeof(IDESC));
486+
v_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->m, p0 * ma->nbrow))
487+
* (size_t)ma->nbrow * sizeof(IDESC));
488488
/* We go for the scanning of indices. For each processor including mypnum,
489489
* we fill the sendbuff buffer (scanD0(SENDBUFF)) and when it is done send
490490
* it. Then for each processor, we compute the size of message to be
@@ -589,7 +589,7 @@ init_chenille(Int mypnum, Int nprocs, Int n0, Int *proc0, Int n1, Int *proc1, In
589589
Int ns, nr, i, tot;
590590
Int *sender, *recver, *g0, *g1;
591591
tot = max(n0, n1);
592-
sender = (Int *) mr2d_malloc((nprocs + tot) * sizeof(Int) * 2);
592+
sender = (Int *) mr2d_malloc((size_t)(nprocs + tot) * sizeof(Int) * 2);
593593
recver = sender + tot;
594594
*psend = sender;
595595
*precv = recver;
@@ -661,7 +661,7 @@ gridreshape(Int *ctxtp)
661661
Int i, j;
662662
ori = *ctxtp;
663663
Cblacs_gridinfo(ori, &nprow, &npcol, &myrow, &mycol);
664-
usermap = mr2d_malloc(sizeof(Int) * nprow * npcol);
664+
usermap = mr2d_malloc(sizeof(Int) * (size_t)nprow * (size_t)npcol);
665665
for (i = 0; i < nprow; i++)
666666
for (j = 0; j < npcol; j++) {
667667
usermap[i + j * nprow] = Cblacs_pnum(ori, i, j);

REDIST/SRC/pdtrmr2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ setmemory(double **adpointer, Int blocksize)
118118
return;
119119
}
120120
*adpointer = (double *) mr2d_malloc(
121-
blocksize * sizeof(double));
121+
(size_t)blocksize * sizeof(double));
122122
}
123123
/******************************************************************/
124124
/* Free the memory space after the malloc */

REDIST/SRC/pgemraux.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ extern void Cpigemr2d();
104104
#include <stdio.h>
105105
#include <stdlib.h>
106106
#include <assert.h>
107+
const size_t NEGFLAG = ~( ((size_t)-1) >> 1);
107108
void *
108-
mr2d_malloc(Int n)
109+
mr2d_malloc(size_t n)
109110
{
110111
void *ptr;
111-
assert(n > 0);
112+
assert((n & NEGFLAG) == 0);
112113
ptr = (void *) malloc(n);
113114
if (ptr == NULL) {
114115
fprintf(stderr, "xxmr2d:out of memory\n");

REDIST/SRC/pigemr.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Cpigemr2d(m, n,
339339
assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
340340
/* exchange the missing parameters among the processors: shape of grids and
341341
* location of the processors */
342-
param = (Int *) mr2d_malloc(3 * (nprocs * 2 + NBPARAM) * sizeof(Int));
342+
param = (Int *) mr2d_malloc(3 * ((size_t)nprocs * 2 + NBPARAM) * sizeof(Int));
343343
ra = param + nprocs * 2 + NBPARAM;
344344
ca = param + (nprocs * 2 + NBPARAM) * 2;
345345
for (i = 0; i < nprocs * 2 + NBPARAM; i++)
@@ -464,10 +464,10 @@ Cpigemr2d(m, n,
464464
/* allocing room for the tabs, alloc for the worst case,local_n or local_m
465465
* intervals, in fact the worst case should be less, perhaps half that,I
466466
* should think of that one day. */
467-
h_inter = (IDESC *) mr2d_malloc(DIVUP(ma->n, q0 * ma->nbcol) *
468-
ma->nbcol * sizeof(IDESC));
469-
v_inter = (IDESC *) mr2d_malloc(DIVUP(ma->m, p0 * ma->nbrow)
470-
* ma->nbrow * sizeof(IDESC));
467+
h_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->n, q0 * ma->nbcol)) *
468+
(size_t)ma->nbcol * sizeof(IDESC));
469+
v_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->m, p0 * ma->nbrow))
470+
* (size_t)ma->nbrow * sizeof(IDESC));
471471
/* We go for the scanning of indices. For each processor including mypnum,
472472
* we fill the sendbuff buffer (scanD0(SENDBUFF)) and when it is done send
473473
* it. Then for each processor, we compute the size of message to be
@@ -567,7 +567,7 @@ init_chenille(Int mypnum, Int nprocs, Int n0, Int *proc0, Int n1, Int *proc1, In
567567
Int ns, nr, i, tot;
568568
Int *sender, *recver, *g0, *g1;
569569
tot = max(n0, n1);
570-
sender = (Int *) mr2d_malloc((nprocs + tot) * sizeof(Int) * 2);
570+
sender = (Int *) mr2d_malloc((size_t)(nprocs + tot) * sizeof(Int) * 2);
571571
recver = sender + tot;
572572
*psend = sender;
573573
*precv = recver;
@@ -703,7 +703,7 @@ gridreshape(Int *ctxtp)
703703
Int i, j;
704704
ori = *ctxtp;
705705
Cblacs_gridinfo(ori, &nprow, &npcol, &myrow, &mycol);
706-
usermap = mr2d_malloc(sizeof(Int) * nprow * npcol);
706+
usermap = mr2d_malloc(sizeof(Int) * (size_t)nprow * (size_t)npcol);
707707
for (i = 0; i < nprow; i++)
708708
for (j = 0; j < npcol; j++) {
709709
usermap[i + j * nprow] = Cblacs_pnum(ori, i, j);

REDIST/SRC/pigemr2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ setmemory(Int **adpointer, Int blocksize)
118118
return;
119119
}
120120
*adpointer = (Int *) mr2d_malloc(
121-
blocksize * sizeof(Int));
121+
(size_t)blocksize * sizeof(Int));
122122
}
123123
/******************************************************************/
124124
/* Free the memory space after the malloc */

REDIST/SRC/pitrmr.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Cpitrmr2d(uplo, diag, m, n,
356356
assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
357357
/* exchange the missing parameters among the processors: shape of grids and
358358
* location of the processors */
359-
param = (Int *) mr2d_malloc(3 * (nprocs * 2 + NBPARAM) * sizeof(Int));
359+
param = (Int *) mr2d_malloc(3 * ((size_t)nprocs * 2 + NBPARAM) * sizeof(Int));
360360
ra = param + nprocs * 2 + NBPARAM;
361361
ca = param + (nprocs * 2 + NBPARAM) * 2;
362362
for (i = 0; i < nprocs * 2 + NBPARAM; i++)
@@ -481,10 +481,10 @@ Cpitrmr2d(uplo, diag, m, n,
481481
/* allocing room for the tabs, alloc for the worst case,local_n or local_m
482482
* intervals, in fact the worst case should be less, perhaps half that,I
483483
* should think of that one day. */
484-
h_inter = (IDESC *) mr2d_malloc(DIVUP(ma->n, q0 * ma->nbcol) *
485-
ma->nbcol * sizeof(IDESC));
486-
v_inter = (IDESC *) mr2d_malloc(DIVUP(ma->m, p0 * ma->nbrow)
487-
* ma->nbrow * sizeof(IDESC));
484+
h_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->n, q0 * ma->nbcol)) *
485+
(size_t)(ma->nbcol) * sizeof(IDESC));
486+
v_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->m, p0 * ma->nbrow))
487+
* (size_t)ma->nbrow * sizeof(IDESC));
488488
/* We go for the scanning of indices. For each processor including mypnum,
489489
* we fill the sendbuff buffer (scanD0(SENDBUFF)) and when it is done send
490490
* it. Then for each processor, we compute the size of message to be
@@ -589,7 +589,7 @@ init_chenille(Int mypnum, Int nprocs, Int n0, Int *proc0, Int n1, Int *proc1, In
589589
Int ns, nr, i, tot;
590590
Int *sender, *recver, *g0, *g1;
591591
tot = max(n0, n1);
592-
sender = (Int *) mr2d_malloc((nprocs + tot) * sizeof(Int) * 2);
592+
sender = (Int *) mr2d_malloc((size_t)(nprocs + tot) * sizeof(Int) * 2);
593593
recver = sender + tot;
594594
*psend = sender;
595595
*precv = recver;
@@ -661,7 +661,7 @@ gridreshape(Int *ctxtp)
661661
Int i, j;
662662
ori = *ctxtp;
663663
Cblacs_gridinfo(ori, &nprow, &npcol, &myrow, &mycol);
664-
usermap = mr2d_malloc(sizeof(Int) * nprow * npcol);
664+
usermap = mr2d_malloc(sizeof(Int) * (size_t)nprow * (size_t)npcol);
665665
for (i = 0; i < nprow; i++)
666666
for (j = 0; j < npcol; j++) {
667667
usermap[i + j * nprow] = Cblacs_pnum(ori, i, j);

REDIST/SRC/pitrmr2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ setmemory(Int **adpointer, Int blocksize)
118118
return;
119119
}
120120
*adpointer = (Int *) mr2d_malloc(
121-
blocksize * sizeof(Int));
121+
(size_t)blocksize * sizeof(Int));
122122
}
123123
/******************************************************************/
124124
/* Free the memory space after the malloc */

REDIST/SRC/psgemr.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Cpsgemr2d(m, n,
339339
assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
340340
/* exchange the missing parameters among the processors: shape of grids and
341341
* location of the processors */
342-
param = (Int *) mr2d_malloc(3 * (nprocs * 2 + NBPARAM) * sizeof(Int));
342+
param = (Int *) mr2d_malloc(3 * ((size_t)nprocs * 2 + NBPARAM) * sizeof(Int));
343343
ra = param + nprocs * 2 + NBPARAM;
344344
ca = param + (nprocs * 2 + NBPARAM) * 2;
345345
for (i = 0; i < nprocs * 2 + NBPARAM; i++)
@@ -464,10 +464,10 @@ Cpsgemr2d(m, n,
464464
/* allocing room for the tabs, alloc for the worst case,local_n or local_m
465465
* intervals, in fact the worst case should be less, perhaps half that,I
466466
* should think of that one day. */
467-
h_inter = (IDESC *) mr2d_malloc(DIVUP(ma->n, q0 * ma->nbcol) *
468-
ma->nbcol * sizeof(IDESC));
469-
v_inter = (IDESC *) mr2d_malloc(DIVUP(ma->m, p0 * ma->nbrow)
470-
* ma->nbrow * sizeof(IDESC));
467+
h_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->n, q0 * ma->nbcol)) *
468+
(size_t)ma->nbcol * sizeof(IDESC));
469+
v_inter = (IDESC *) mr2d_malloc((size_t)(DIVUP(ma->m, p0 * ma->nbrow))
470+
* (size_t)ma->nbrow * sizeof(IDESC));
471471
/* We go for the scanning of indices. For each processor including mypnum,
472472
* we fill the sendbuff buffer (scanD0(SENDBUFF)) and when it is done send
473473
* it. Then for each processor, we compute the size of message to be
@@ -567,7 +567,7 @@ init_chenille(Int mypnum, Int nprocs, Int n0, Int *proc0, Int n1, Int *proc1, In
567567
Int ns, nr, i, tot;
568568
Int *sender, *recver, *g0, *g1;
569569
tot = max(n0, n1);
570-
sender = (Int *) mr2d_malloc((nprocs + tot) * sizeof(Int) * 2);
570+
sender = (Int *) mr2d_malloc((size_t)(nprocs + tot) * sizeof(Int) * 2);
571571
recver = sender + tot;
572572
*psend = sender;
573573
*precv = recver;
@@ -703,7 +703,7 @@ gridreshape(Int *ctxtp)
703703
Int i, j;
704704
ori = *ctxtp;
705705
Cblacs_gridinfo(ori, &nprow, &npcol, &myrow, &mycol);
706-
usermap = mr2d_malloc(sizeof(Int) * nprow * npcol);
706+
usermap = mr2d_malloc(sizeof(Int) * (size_t)nprow * (size_t)npcol);
707707
for (i = 0; i < nprow; i++)
708708
for (j = 0; j < npcol; j++) {
709709
usermap[i + j * nprow] = Cblacs_pnum(ori, i, j);

REDIST/SRC/psgemr2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ setmemory(float **adpointer, Int blocksize)
118118
return;
119119
}
120120
*adpointer = (float *) mr2d_malloc(
121-
blocksize * sizeof(float));
121+
(size_t)blocksize * sizeof(float));
122122
}
123123
/******************************************************************/
124124
/* Free the memory space after the malloc */

0 commit comments

Comments
 (0)