From 8d07869da261032cbf6ee578ee32a8a02ff6df99 Mon Sep 17 00:00:00 2001 From: Qinglei Cao Date: Fri, 15 Mar 2024 15:21:43 +0000 Subject: [PATCH] Fix overflow when calling parsec_data_create --- parsec/data_dist/matrix/matrix.c | 11 ++++++----- parsec/data_dist/matrix/matrix.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/parsec/data_dist/matrix/matrix.c b/parsec/data_dist/matrix/matrix.c index be662cba5..8b8b79403 100644 --- a/parsec/data_dist/matrix/matrix.c +++ b/parsec/data_dist/matrix/matrix.c @@ -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; @@ -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 ); @@ -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; @@ -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; diff --git a/parsec/data_dist/matrix/matrix.h b/parsec/data_dist/matrix/matrix.h index 24fe57463..b80b518fe 100644 --- a/parsec/data_dist/matrix/matrix.h +++ b/parsec/data_dist/matrix/matrix.h @@ -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 */