Skip to content

Commit

Permalink
Fix overflow when calling parsec_data_create
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinglei Cao committed May 3, 2024
1 parent 74d9dcd commit 8d07869
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions parsec/data_dist/matrix/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void parsec_tiled_matrix_init( parsec_tiled_matrix_t *tdesc,
tdesc->tileld = (storage == PARSEC_MATRIX_TILE) ? mb : lm;
tdesc->mb = mb;
tdesc->nb = nb;
tdesc->bsiz = mb * nb;
tdesc->bsiz = (size_t)mb * nb;

/* Large matrix parameters */
tdesc->lm = lm;
Expand Down Expand Up @@ -304,7 +304,8 @@ int parsec_tiled_matrix_data_read(parsec_tiled_matrix_t *tdesc, char *filename)
parsec_data_t* data;
FILE *tmpf;
char *buf;
int i, j, k, ret;
int i, j, k;
size_t ret;
uint32_t myrank = tdesc->super.myrank;
int eltsize = parsec_datadist_getsizeoftype( tdesc->mtype );

Expand All @@ -322,7 +323,7 @@ int parsec_tiled_matrix_data_read(parsec_tiled_matrix_t *tdesc, char *filename)
buf = parsec_data_get_ptr(data, 0);
ret = fread(buf, eltsize, tdesc->bsiz, tmpf );
if ( ret != tdesc->bsiz ) {
parsec_warning("The read on tile(%d, %d) read %d elements instead of %d",
parsec_warning("The read on tile(%d, %d) read %zu elements instead of %zu",
i, j, ret, tdesc->bsiz);
fclose(tmpf);
return PARSEC_ERR_TRUNCATE;
Expand All @@ -337,8 +338,8 @@ int parsec_tiled_matrix_data_read(parsec_tiled_matrix_t *tdesc, char *filename)
buf = parsec_data_get_ptr(data, 0);
for (k=0; k < tdesc->nb; k++) {
ret = fread(buf, eltsize, tdesc->mb, tmpf );
if ( ret != tdesc->mb ) {
parsec_warning("The read on tile(%d, %d) read %d elements instead of %d",
if ( ret != (size_t)tdesc->mb ) {
parsec_warning("The read on tile(%d, %d) read %zu elements instead of %d",
i, j, ret, tdesc->mb);
fclose(tmpf);
return PARSEC_ERR_TRUNCATE;
Expand Down
2 changes: 1 addition & 1 deletion parsec/data_dist/matrix/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ typedef struct parsec_tiled_matrix_s {
int tileld; /**< leading dimension of each tile (Should be a function depending on the row) */
int mb; /**< number of rows in a tile */
int nb; /**< number of columns in a tile */
int bsiz; /**< size in elements including padding of a tile - derived parameter */
size_t bsiz; /**< size in elements including padding of a tile - derived parameter */
int lm; /**< number of rows of the entire matrix */
int ln; /**< number of columns of the entire matrix */
int lmt; /**< number of tile rows of the entire matrix - derived parameter */
Expand Down

0 comments on commit 8d07869

Please sign in to comment.