diff --git a/benchmarks/C/aggregation.c b/benchmarks/C/aggregation.c index 3f29fd4f4..71aa3de53 100644 --- a/benchmarks/C/aggregation.c +++ b/benchmarks/C/aggregation.c @@ -184,13 +184,13 @@ int benchmark_write(char *filename, if (cfg->star_block) nvars++; nvars *= cfg->nvars; - varid = (int*) malloc(nvars * sizeof(int)); + varid = (int*) malloc(sizeof(int) * nvars); /* initialize I/O buffer */ lenlen = cfg->len * cfg->len; - buf = (double**) malloc(nvars * sizeof(double*)); + buf = (double**) malloc(sizeof(double*) * nvars); for (i=0; iheader_size); ERR(err) @@ -436,9 +436,9 @@ int benchmark_read(char *filename, nvars *= cfg->nvars; /* allocate I/O buffer */ - buf = (double**) malloc(nvars * sizeof(double*)); + buf = (double**) malloc(sizeof(double*) * nvars); for (i=0; istar_block) num_reqs++; /* complete in 1 nonblocking call */ } - reqs = (int*) malloc(num_reqs * sizeof(int)); - sts = (int*) malloc(num_reqs * sizeof(int)); + reqs = (int*) malloc(sizeof(int) * num_reqs); + sts = (int*) malloc(sizeof(int) * num_reqs); timing[2] = timing[3] = 0; for (n=0; nnum_records; n++) { diff --git a/benchmarks/C/write_block_read_column.c b/benchmarks/C/write_block_read_column.c index 29cb05a81..4c129794c 100644 --- a/benchmarks/C/write_block_read_column.c +++ b/benchmarks/C/write_block_read_column.c @@ -91,22 +91,22 @@ int benchmark_write(char *filename, /* initialize I/O buffer */ for (i=0; i 0) buf[i] = buf[i-1] + global_ny; for (j=0; j 0) { - starts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*)); - counts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*)); + starts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); + counts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); starts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset)); counts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset)); for (i=1; i 0) bufs[0] = buffer; for (i=1; ifname, id); /* allocate I/O buffers and initialize their contents */ - ibuf = (int*) malloc(NY * NX * sizeof(int)); - dbuf = (double*) malloc(NY * NX * sizeof(double)); + ibuf = (int*) malloc(sizeof(int) * NY * NX); + dbuf = (double*) malloc(sizeof(double) * NY * NX); for (i=0; i 0) { - starts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*)); + starts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); starts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset)); for (i=1; i 0) { - starts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*)); - counts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*)); + starts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); + counts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); starts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset)); counts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset)); for (i=1; i 0) buf[i] = buf[i-1] + NY; for (j=0; j start(2), count(2); @@ -190,7 +190,7 @@ int main(int argc, char** argv) /* allocate buffer buf_yx and initialize its contents */ buffer_len = (NY+2*ghost_len) * (NX+2*ghost_len); - buf_yx = (float*) malloc(buffer_len * sizeof(float)); + buf_yx = (float*) malloc(sizeof(float) * buffer_len); for (i=0; i start(2), count(2); diff --git a/examples/CXX/hints.cpp b/examples/CXX/hints.cpp index bd9b0bb30..23a9db90e 100644 --- a/examples/CXX/hints.cpp +++ b/examples/CXX/hints.cpp @@ -158,7 +158,7 @@ int main(int argc, char** argv) NcmpiVar var1 = ncFile.addVar("var_yx", ncmpiFloat, dimid_yx); /* var_zy is partitioned along Z dimension */ - buf_zy = (int*) malloc(NZ * (NY * nprocs) * sizeof(int)); + buf_zy = (int*) malloc(sizeof(int) * NZ * (NY * nprocs)); for (i=0; i 0) { - starts = (MPI_Offset**)malloc(num_reqs* sizeof(MPI_Offset*)); + starts = (MPI_Offset**)malloc(sizeof(MPI_Offset*) * num_reqs); starts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset)); for (i=1; i 0) { - starts = (MPI_Offset**) malloc(num_reqs * sizeof(MPI_Offset*)); - counts = (MPI_Offset**) malloc(num_reqs * sizeof(MPI_Offset*)); + starts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); + counts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); starts[0] = (MPI_Offset*) calloc(num_reqs * NDIMS, sizeof(MPI_Offset)); counts[0] = (MPI_Offset*) calloc(num_reqs * NDIMS, sizeof(MPI_Offset)); for (i=1; i v$count) p--; p++; while (*pin == ' ' && pin < p) pin++; - p$count = (char *)$malloc( (size_t)(p-pin) + 1 ); + p$count = (char *)$malloc((size_t)(p-pin) + 1); for (li=0; li<(p-pin); li++) { p$count\[li\] = pin\[li\]; } p$count\[li\] = '\\0'; } @@ -1919,8 +1919,8 @@ sub chararray_ftoc { }\n"; } print $OUTFD "\ - p$count = (char **)$malloc( (size_t)asize$count * sizeof(char *) ); - ptmp = (char *)$malloc( (size_t)asize$count * (d$count + 1) ); + p$count = (char **)$malloc(sizeof(char *) * (asize$count)); + ptmp = (char *)$malloc((size_t)asize$count * (d$count + 1)); for (i=0; i 0) { int li; - l$count = (MPI_Aint *)$malloc( (size_t)($Array_size) * SIZEOF_MPI_AINT ); + l$count = (MPI_Aint *)$malloc(sizeof(MPI_Aint) * ($Array_size)); for (li=0; li<$Array_size; li++) l$count\[li\] = v$count\[li\]; } diff --git a/src/binding/f77/defs b/src/binding/f77/defs index c504139dc..6b40078a2 100644 --- a/src/binding/f77/defs +++ b/src/binding/f77/defs @@ -2066,7 +2066,7 @@ sub intToFintArr_ftoc { print $OUTFD " { int li; - l$count = (int*) $malloc((size_t)$Array_size * sizeof(int)); + l$count = (int*) $malloc(sizeof(int) * ($Array_size)); for (li=0; li<$Array_size; li++) l$count\[li\] = v$count\[li\]; /* convert MPI_Fint to C int */ }\n"; @@ -2074,7 +2074,7 @@ sub intToFintArr_ftoc { sub intToFintArr_out_ftoc { my $count = $_[0]; print $OUTFD " - l$count = (int*) $malloc((size_t)$Array_size * sizeof(int)); + l$count = (int*) $malloc(sizeof(int) * ($Array_size)); \n"; } sub intToFintArr_in_arg { @@ -2178,7 +2178,7 @@ sub reorderOffsetArr_ftoc { ierr = ncmpi_inq_varndims((int)(*v1), (int)(*v2-1), &ndims); /* get number of dimensions */ if (ierr != NC_NOERR) return ierr; - l$count = (MPI_Offset*) $malloc((size_t)ndims * $Array_size * SIZEOF_MPI_OFFSET); + l$count = (MPI_Offset*) $malloc(sizeof(MPI_Offset) * ndims * ($Array_size)); for (li=0; li 0) { - l$count = (MPI_Offset**) $malloc((size_t)*v3 * sizeof(MPI_Offset*)); - l$count\[0\] = (MPI_Offset*) $malloc((size_t)*v3 * (size_t)ndims * SIZEOF_MPI_OFFSET); + l$count = (MPI_Offset**) $malloc(sizeof(MPI_Offset*) * (*v3)); + l$count\[0\] = (MPI_Offset*) $malloc(sizeof(MPI_Offset) * (*v3) * (size_t)ndims); } for (lj=1; lj<*v3; lj++) l$count\[lj\] = l$count\[lj-1\] + ndims; @@ -2282,7 +2282,7 @@ sub reorderIntArr_ftoc { if (ierr != NC_NOERR) return ierr;\n" } print $OUTFD " - l$count = (int*) $malloc((size_t)ndims * SIZEOF_INT); + l$count = (int*) $malloc(sizeof(int) * ndims); for (li=0; li 0) { int li; - l$count = (int*) $malloc( (size_t)ln$count * SIZEOF_INT); + l$count = (int*) $malloc(sizeof(int) * ln$count); for (li=0; livars[] */ nalloc = PNETCDF_RNDUP(pncp->nvars, PNC_VARS_CHUNK); - pncp->vars = NCI_Malloc(nalloc * sizeof(PNC_var)); + pncp->vars = NCI_Malloc(sizeof(PNC_var) * nalloc); if (pncp->vars == NULL) { DEBUG_ASSIGN_ERROR(err, NC_ENOMEM) goto fn_exit; @@ -835,10 +835,10 @@ ncmpi_open(MPI_Comm comm, if (ndims > 0) { pncp->vars[i].shape = (MPI_Offset*) - NCI_Malloc(ndims * SIZEOF_MPI_OFFSET); + NCI_Malloc(sizeof(MPI_Offset) * ndims); if (ndims > max_ndims) { /* avoid repeated malloc */ if (dimids == DIMIDS) dimids = NULL; - dimids = (int*) NCI_Realloc(dimids, ndims * SIZEOF_INT); + dimids = (int*) NCI_Realloc(dimids, sizeof(int) * ndims); max_ndims = ndims; } err = driver->inq_var(pncp->ncp, i, NULL, NULL, NULL, diff --git a/src/dispatchers/var_getput.m4 b/src/dispatchers/var_getput.m4 index 671697ca2..30d80c76c 100644 --- a/src/dispatchers/var_getput.m4 +++ b/src/dispatchers/var_getput.m4 @@ -27,14 +27,14 @@ define(`GOTO_CHECK',`{ DEBUG_ASSIGN_ERROR(err, $1) goto err_check; }')dnl #define GET_ONE_COUNT(ndims, count) { \ int _i; \ - count = (MPI_Offset*) NCI_Malloc((size_t)ndims * SIZEOF_MPI_OFFSET); \ + count = (MPI_Offset*) NCI_Malloc(sizeof(MPI_Offset) * ndims); \ for (_i=0; _i 0) { - int *root_dimids = (int*)NCI_Malloc((size_t)root_ndims *SIZEOF_INT); + int *root_dimids = (int*)NCI_Malloc(sizeof(int) * root_ndims); if (dimids != NULL) - memcpy(root_dimids, dimids, (size_t)root_ndims*SIZEOF_INT); + memcpy(root_dimids, dimids, sizeof(int) * root_ndims); else - memset(root_dimids, 0, (size_t)root_ndims*SIZEOF_INT); + memset(root_dimids, 0, sizeof(int) * root_ndims); TRACE_COMM(MPI_Bcast)(root_dimids, root_ndims,MPI_INT,0,pncp->comm); if (mpireturn != MPI_SUCCESS) { NCI_Free(root_dimids); return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast"); } if (err == NC_NOERR && dimids != NULL && - memcmp(root_dimids, dimids, (size_t)root_ndims*SIZEOF_INT)) + memcmp(root_dimids, dimids, sizeof(int) * root_ndims)) DEBUG_ASSIGN_ERROR(err, NC_EMULTIDEFINE_VAR_DIMIDS) NCI_Free(root_dimids); } @@ -222,7 +222,7 @@ ncmpi_def_var(int ncid, /* IN: file ID */ } pncp->vars[*varidp].shape = (MPI_Offset*) - NCI_Malloc(ndims * SIZEOF_MPI_OFFSET); + NCI_Malloc(sizeof(MPI_Offset) * ndims); for (i=0; idriver->inq_dim(pncp->ncp, dimids[i], NULL, diff --git a/src/drivers/common/dtype_decode.c b/src/drivers/common/dtype_decode.c index 4012943c9..99dc78ff3 100644 --- a/src/drivers/common/dtype_decode.c +++ b/src/drivers/common/dtype_decode.c @@ -361,9 +361,9 @@ int ncmpii_dtype_decode(MPI_Datatype dtype, return NC_NOERR; } - array_of_ints = (int *) NCI_Malloc((size_t)num_ints * SIZEOF_INT); - array_of_adds = (MPI_Aint *) NCI_Malloc((size_t)num_adds * SIZEOF_MPI_AINT); - array_of_dtypes = (MPI_Datatype *) NCI_Malloc((size_t)num_dtypes * sizeof(MPI_Datatype)); + array_of_ints = (int *) NCI_Malloc(sizeof(int) * num_ints); + array_of_adds = (MPI_Aint *) NCI_Malloc(sizeof(MPI_Aint) * num_adds); + array_of_dtypes = (MPI_Datatype *) NCI_Malloc(sizeof(MPI_Datatype)* num_dtypes); if (is_large_type) { #ifdef HAVE_MPI_LARGE_COUNT diff --git a/src/drivers/common/hash_map.c b/src/drivers/common/hash_map.c index ca45d9f6f..2f3bf1309 100644 --- a/src/drivers/common/hash_map.c +++ b/src/drivers/common/hash_map.c @@ -74,7 +74,7 @@ int hash_map_add(hash_map *map, char *key, int val) { if (new_node == NULL){ DEBUG_RETURN_ERROR(NC_ENOMEM); } - new_node->key = (char*)NCI_Malloc((strlen(key) + 1) * sizeof(char)); + new_node->key = (char*)NCI_Malloc(sizeof(char) * (strlen(key) + 1)); if (new_node->key == NULL){ NCI_Free(new_node); DEBUG_RETURN_ERROR(NC_ENOMEM); diff --git a/src/drivers/common/utf8proc.c b/src/drivers/common/utf8proc.c index 6beb6349b..b5c5ab4b7 100644 --- a/src/drivers/common/utf8proc.c +++ b/src/drivers/common/utf8proc.c @@ -826,7 +826,7 @@ UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map_custom( *dstptr = NULL; result = utf8proc_decompose_custom(str, strlen, NULL, 0, options, custom_func, custom_data); if (result < 0) return result; - buffer = (utf8proc_int32_t *) NCI_Malloc(result * sizeof(utf8proc_int32_t) + 1); + buffer = (utf8proc_int32_t *) NCI_Malloc(sizeof(utf8proc_int32_t) * result + 1); if (!buffer) return UTF8PROC_ERROR_NOMEM; result = utf8proc_decompose_custom(str, strlen, buffer, result, options, custom_func, custom_data); if (result < 0) { diff --git a/src/drivers/nc4io/nc4io_file.c b/src/drivers/nc4io/nc4io_file.c index b19ce526f..7e1c704fa 100644 --- a/src/drivers/nc4io/nc4io_file.c +++ b/src/drivers/nc4io/nc4io_file.c @@ -376,13 +376,13 @@ nc4io_inq_misc(void *ncdp, */ err = nc_inq(nc4p->ncid, &ndim, NULL, NULL, NULL); if (err != NC_NOERR) DEBUG_RETURN_ERROR(err); - isrec = (int*)NCI_Malloc(SIZEOF_INT * ndim); - memset(isrec, 0, SIZEOF_INT * ndim); + isrec = (int*)NCI_Malloc(sizeof(int) * ndim); + memset(isrec, 0, sizeof(int) * ndim); /* Get list of unlimited dim */ err = nc_inq_unlimdims(nc4p->ncid, &nrecdim, NULL); if (err != NC_NOERR) DEBUG_RETURN_ERROR(err) - recdims = (int*)NCI_Malloc(SIZEOF_INT * nrecdim); + recdims = (int*)NCI_Malloc(sizeof(int) * nrecdim); err = nc_inq_unlimdims(nc4p->ncid, NULL, recdims); if (err != NC_NOERR) DEBUG_RETURN_ERROR(err) @@ -395,7 +395,7 @@ nc4io_inq_misc(void *ncdp, err = nc_inq_varids(nc4p->ncid, &nvar, NULL); if (err != NC_NOERR) DEBUG_RETURN_ERROR(err) - vars = NCI_Malloc(SIZEOF_INT * nvar); + vars = NCI_Malloc(sizeof(int) * nvar); if (vars == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM) /* IDs of all variables */ @@ -415,7 +415,7 @@ nc4io_inq_misc(void *ncdp, err = nc_inq_varndims(nc4p->ncid, vars[i], &ndim); if (err != NC_NOERR) DEBUG_RETURN_ERROR(err); - dims = NCI_Malloc(SIZEOF_INT * ndim); + dims = NCI_Malloc(sizeof(int) * ndim); if (dims == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM); /* IDs of dimensions */ diff --git a/src/drivers/ncadios/ncadios_bp2ncd.c b/src/drivers/ncadios/ncadios_bp2ncd.c index 9de53eede..d985ec093 100644 --- a/src/drivers/ncadios/ncadios_bp2ncd.c +++ b/src/drivers/ncadios/ncadios_bp2ncd.c @@ -462,9 +462,9 @@ int ncadiosi_parse_header_bp2ncd (NC_ad *ncid) uint32_t version = 0; is_input_fortran = 0; - b = malloc (sizeof (struct adios_bp_buffer_struct_v1)); - b_0 = malloc (sizeof (struct adios_bp_buffer_struct_v1)); - b_1 = malloc (sizeof (struct adios_bp_buffer_struct_v1)); + b = malloc(sizeof(struct adios_bp_buffer_struct_v1)); + b_0 = malloc(sizeof(struct adios_bp_buffer_struct_v1)); + b_1 = malloc(sizeof(struct adios_bp_buffer_struct_v1)); adios_buffer_struct_init (b); rc = adios_posix_open_read_internal (ncid->path, "", b); @@ -597,14 +597,14 @@ int ncadiosi_parse_header_bp2ncd (NC_ad *ncid) err = adios_parse_var_data_header_v1 (b, &var_header); if (var_header.is_dim == adios_flag_yes) { - var_payload.payload = malloc (var_header.payload_size); + var_payload.payload = malloc(var_header.payload_size); err = adios_parse_var_data_payload_v1 (b, &var_header, &var_payload ,var_header.payload_size ); } else { /* alloc size +1 to remove valgrind complaint */ - var_payload.payload = malloc (var_header.payload_size + 1); + var_payload.payload = malloc(var_header.payload_size + 1); err = adios_parse_var_data_payload_v1 (b, &var_header, &var_payload ,var_header.payload_size ); diff --git a/src/drivers/ncadios/ncadios_internal.c b/src/drivers/ncadios/ncadios_internal.c index e0a880a36..7443d0df7 100644 --- a/src/drivers/ncadios/ncadios_internal.c +++ b/src/drivers/ncadios/ncadios_internal.c @@ -54,8 +54,8 @@ int ncadiosi_def_var(NC_ad* ncadp, char* name, nc_type type, int ndim, if (CHECK_NAME(name)){ var.type = type; var.ndim = ndim; - var.dimids = NCI_Malloc(SIZEOF_INT * ndim); - memcpy(var.dimids, dimids, SIZEOF_INT * ndim); + var.dimids = NCI_Malloc(sizeof(int) * ndim); + memcpy(var.dimids, dimids, sizeof(int) * ndim); var.name = NCI_Malloc(strlen(name) + 1); strcpy(var.name, name); ncadiosi_att_list_init(&(var.atts)); @@ -167,7 +167,7 @@ int ncadiosi_parse_header_readall (NC_ad *ncadp) { if (dimids != NULL){ NCI_Free(dimids); } - dimids = (int*)NCI_Malloc(SIZEOF_INT * maxndim); + dimids = (int*)NCI_Malloc(sizeof(int) * maxndim); } /* Record every dimensions */ diff --git a/src/drivers/ncadios/ncadios_lists.c b/src/drivers/ncadios/ncadios_lists.c index 738ed295d..3bf4e29cb 100644 --- a/src/drivers/ncadios/ncadios_lists.c +++ b/src/drivers/ncadios/ncadios_lists.c @@ -73,7 +73,7 @@ int ncadiosi_var_list_add(NC_ad_var_list *list, NC_ad_var data) { if (list->nalloc == 0){ list->nalloc = 16; - list->data = NCI_Malloc(list->nalloc * sizeof(NC_ad_var)); + list->data = NCI_Malloc(sizeof(NC_ad_varp) * list->nalloc); } else if (list->nalloc == id){ list->nalloc *= 2; @@ -93,7 +93,7 @@ int ncadiosi_dim_list_add(NC_ad_dim_list *list, NC_ad_dim data) { if (list->nalloc == 0){ list->nalloc = 16; - list->data = NCI_Malloc(list->nalloc * sizeof(NC_ad_dim)); + list->data = NCI_Malloc(sizeof(NC_ad_dim) * list->nalloc); } else if (list->nalloc == id){ list->nalloc *= 2; @@ -113,11 +113,11 @@ int ncadiosi_att_list_add(NC_ad_att_list *list, int data) { if (list->nalloc == 0){ list->nalloc = 16; - list->data = NCI_Malloc(list->nalloc * SIZEOF_INT); + list->data = NCI_Malloc(sizeof(int) * list->nalloc); } else if (list->nalloc == id){ list->nalloc *= 2; - list->data = NCI_Realloc(list->data, list->nalloc * SIZEOF_INT); + list->data = NCI_Realloc(list->data, list->nalloc * sizeof(int)); } list->data[id] = data; diff --git a/src/drivers/ncadios/ncadios_nonblocking.c b/src/drivers/ncadios/ncadios_nonblocking.c index 565bc1b9e..ddb17aee3 100644 --- a/src/drivers/ncadios/ncadios_nonblocking.c +++ b/src/drivers/ncadios/ncadios_nonblocking.c @@ -76,9 +76,9 @@ int ncadiosi_get_list_init(NC_ad_get_list *lp) { /* Initialize parameter and allocate the array */ lp->nused = 0; lp->nalloc = PUT_ARRAY_SIZE; - lp->reqs = (NC_ad_get_req*)NCI_Malloc(lp->nalloc * sizeof(NC_ad_get_req)); - lp->ids = (int*)NCI_Malloc(lp->nalloc * SIZEOF_INT); - lp->pos = (int*)NCI_Malloc(lp->nalloc * SIZEOF_INT); + lp->reqs = (NC_ad_get_req*)NCI_Malloc(sizeof(NC_ad_get_req) * lp->nalloc); + lp->ids = (int*)NCI_Malloc(sizeof(int) * lp->nalloc); + lp->pos = (int*)NCI_Malloc(sizeof(int) * lp->nalloc); if (lp->reqs == NULL || lp->ids == NULL) { DEBUG_RETURN_ERROR(NC_ENOMEM); } @@ -114,11 +114,11 @@ static int ncadiosi_get_list_resize(NC_ad_get_list *lp) if (ptr == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM); lp->reqs = (NC_ad_get_req*)ptr; - ptr = NCI_Realloc(lp->ids, nsize * SIZEOF_INT); + ptr = NCI_Realloc(lp->ids, sizeof(int) * nsize); if (ptr == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM); lp->ids = (int*)ptr; - ptr = NCI_Realloc(lp->pos, nsize * SIZEOF_INT); + ptr = NCI_Realloc(lp->pos, sizeof(int) * nsize); if (ptr == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM); lp->pos = (int*)ptr; diff --git a/src/drivers/ncbbio/ncbbio_file.c b/src/drivers/ncbbio/ncbbio_file.c index 26d4f105f..271f1b969 100644 --- a/src/drivers/ncbbio/ncbbio_file.c +++ b/src/drivers/ncbbio/ncbbio_file.c @@ -567,7 +567,7 @@ ncbbio_cancel(void *ncdp, * req_ids. We do onw swap for each put request, so there are at most * num_req swaps. */ - swapidx = (int*)NCI_Malloc(SIZEOF_INT * num_req); + swapidx = (int*)NCI_Malloc(sizeof(int) * num_req); /* Count the number of put requests and swap it to the first section. nput * is number of put request known so far, it also mark the end of the first @@ -755,7 +755,7 @@ ncbbio_wait(void *ncdp, * req_ids. We do onw swap for each put request, so there are at most * num_reqs swaps */ - swapidx = (int*)NCI_Malloc(SIZEOF_INT * num_reqs); + swapidx = (int*)NCI_Malloc(sizeof(int) * num_reqs); /* Count the number of put requests and swap it to the first section * nput is number of put request known so far, it also mark the end of the diff --git a/src/drivers/ncbbio/ncbbio_log.c b/src/drivers/ncbbio/ncbbio_log.c index 5b22b8339..a16fe9ddc 100644 --- a/src/drivers/ncbbio/ncbbio_log.c +++ b/src/drivers/ncbbio/ncbbio_log.c @@ -87,7 +87,7 @@ int ncbbio_log_create(NC_bb* ncbbp, } else { size_t i = strlen(path); - fdir = (char*)NCI_Malloc((i + 1) * sizeof(char)); + fdir = (char*)NCI_Malloc(sizeof(char) * (i + 1)); strncpy(fdir, path, i + 1); /* Search for first '\' from the back */ for (i--; i > -1; i--) { diff --git a/src/drivers/ncbbio/ncbbio_log_flush.c b/src/drivers/ncbbio/ncbbio_log_flush.c index a87ee249a..5b4687874 100644 --- a/src/drivers/ncbbio/ncbbio_log_flush.c +++ b/src/drivers/ncbbio/ncbbio_log_flush.c @@ -154,8 +154,8 @@ int ncbbio_log_flush_core(NC_bb *ncbbp) { } - reqids = (int*)NCI_Malloc(ncbbp->entrydatasize.nused * SIZEOF_INT); - stats = (int*)NCI_Malloc(ncbbp->entrydatasize.nused * SIZEOF_INT); + reqids = (int*)NCI_Malloc(sizeof(int) * ncbbp->entrydatasize.nused); + stats = (int*)NCI_Malloc(sizeof(int) * ncbbp->entrydatasize.nused); /* * Iterate through meta log entries @@ -299,7 +299,7 @@ int ncbbio_log_flush_core(NC_bb *ncbbp) { #endif /* Replay event with non-blocking call */ - if ((size_t)(entryp->esize) == sizeof(NC_bb_metadataentry) + entryp->ndims * SIZEOF_MPI_OFFSET * num){ + if ((size_t)(entryp->esize) == sizeof(NC_bb_metadataentry) + sizeof(MPI_Offset) * entryp->ndims * num){ err = ncbbp->ncmpio_driver->iput_varn(ncbbp->ncp, entryp->varid, num, starts, NULL, (void*)(databufferoff), -1, buftype, reqids + j, NC_REQ_WR | NC_REQ_NBI | NC_REQ_HL); } else{ diff --git a/src/drivers/ncbbio/ncbbio_mem.c b/src/drivers/ncbbio/ncbbio_mem.c index d5b82d628..8e71959d5 100644 --- a/src/drivers/ncbbio/ncbbio_mem.c +++ b/src/drivers/ncbbio/ncbbio_mem.c @@ -86,7 +86,7 @@ char* ncbbio_log_buffer_alloc(NC_bb_buffer *bp, size_t size) { * IN ep: array to be initialized */ int ncbbio_log_sizearray_init(NC_bb_sizevector *sp){ - sp->values = (size_t*)NCI_Malloc(LOG_ARRAY_SIZE * sizeof(size_t)); + sp->values = (size_t*)NCI_Malloc(sizeof(size_t) * LOG_ARRAY_SIZE); if (sp->values == NULL){ DEBUG_RETURN_ERROR(NC_ENOMEM); } @@ -144,7 +144,7 @@ int ncbbio_log_sizearray_append(NC_bb_sizevector *sp, size_t size) { * IN vp: vector to be initialized */ int ncbbio_log_intvector_init(NC_bb_intvector *vp){ - vp->values = (int*)NCI_Malloc(LOG_ARRAY_SIZE * SIZEOF_INT); + vp->values = (int*)NCI_Malloc(sizeof(int) * LOG_ARRAY_SIZE); if (vp->values == NULL){ DEBUG_RETURN_ERROR(NC_ENOMEM); } @@ -181,7 +181,7 @@ int ncbbio_log_intvector_append(NC_bb_intvector *vp, int size) { */ size_t newsize = vp->nalloc * SIZE_MULTIPLIER; /* ret is used to temporaryly hold the allocated buffer so we don't lose ncbbp->metadata.buffer if allocation fails */ - ret = (int*)NCI_Realloc(vp->values, newsize * SIZEOF_INT); + ret = (int*)NCI_Realloc(vp->values, sizeof(int) * newsize); /* If not enough memory */ if (ret == NULL) { return NC_ENOMEM; diff --git a/src/drivers/ncbbio/ncbbio_misc.c b/src/drivers/ncbbio/ncbbio_misc.c index 35b9d863e..897a9436b 100644 --- a/src/drivers/ncbbio/ncbbio_misc.c +++ b/src/drivers/ncbbio/ncbbio_misc.c @@ -39,8 +39,8 @@ int ncbbio_get_node_comm(MPI_Comm global_comm, MPI_Comm *node_comm) hash_map_init(&map, 65535, hash); - myname = (char*)NCI_Malloc(MPI_MAX_PROCESSOR_NAME * sizeof(char)); - buf = (char*)NCI_Malloc(MPI_MAX_PROCESSOR_NAME * sizeof(char) * np); + myname = (char*)NCI_Malloc(MPI_MAX_PROCESSOR_NAME); + buf = (char*)NCI_Malloc(MPI_MAX_PROCESSOR_NAME * np); err = MPI_Get_processor_name(myname, &namelen); if (err != MPI_SUCCESS){ diff --git a/src/drivers/ncbbio/ncbbio_nonblocking.c b/src/drivers/ncbbio/ncbbio_nonblocking.c index 317090512..8a1c2b31f 100644 --- a/src/drivers/ncbbio/ncbbio_nonblocking.c +++ b/src/drivers/ncbbio/ncbbio_nonblocking.c @@ -63,8 +63,8 @@ int ncbbio_put_list_init(NC_bb *ncbbp) { /* Initialize parameter and allocate the array */ lp->nused = 0; lp->nalloc = PUT_ARRAY_SIZE; - lp->reqs = (NC_bb_put_req*)NCI_Malloc(lp->nalloc * sizeof(NC_bb_put_req)); - lp->ids = (int*)NCI_Malloc(lp->nalloc * SIZEOF_INT); + lp->reqs = (NC_bb_put_req*)NCI_Malloc(sizeof(NC_bb_put_req) * lp->nalloc); + lp->ids = (int*)NCI_Malloc(sizeof(int) * lp->nalloc); if (lp->reqs == NULL || lp->ids == NULL) { DEBUG_RETURN_ERROR(NC_ENOMEM); } @@ -100,7 +100,7 @@ static int ncbbio_put_list_resize(NC_bb *ncbbp) if (ptr == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM); lp->reqs = (NC_bb_put_req*)ptr; - ptr = NCI_Realloc(lp->ids, nsize * SIZEOF_INT); + ptr = NCI_Realloc(lp->ids, sizeof(int) * nsize); if (ptr == NULL) DEBUG_RETURN_ERROR(NC_ENOMEM); lp->ids = (int*)ptr; diff --git a/src/drivers/ncmpio/ncmpio_enddef.c b/src/drivers/ncmpio/ncmpio_enddef.c index 21606f683..b33e00d4a 100644 --- a/src/drivers/ncmpio/ncmpio_enddef.c +++ b/src/drivers/ncmpio/ncmpio_enddef.c @@ -80,7 +80,7 @@ move_file_block(NC *ncp, if (nbytes >= p_units) do_open = 1; else { - int n_units = nbytes / MOVE_UNIT; + MPI_Offset n_units = nbytes / MOVE_UNIT; if (nbytes % MOVE_UNIT) n_units++; if (rank < n_units) do_open = 1; } @@ -943,7 +943,7 @@ ncmpio_NC_check_voffs(NC *ncp) if (num_fix_vars == 0) goto check_rec_var; /* check non-record variables first */ - var_off_len = (off_len*) NCI_Malloc(num_fix_vars * sizeof(off_len)); + var_off_len = (off_len*) NCI_Malloc(sizeof(off_len) * num_fix_vars); for (i=0, j=0; ivars.ndefined; i++) { NC_var *varp = ncp->vars.value[i]; if (varp->begin < ncp->xsz) { @@ -1000,7 +1000,7 @@ ncmpio_NC_check_voffs(NC *ncp) if (ncp->vars.num_rec_vars == 0) return NC_NOERR; /* check record variables */ - var_off_len = (off_len*) NCI_Malloc(ncp->vars.num_rec_vars * sizeof(off_len)); + var_off_len = (off_len*) NCI_Malloc(sizeof(off_len) * ncp->vars.num_rec_vars); for (i=0, j=0; ivars.ndefined; i++) { NC_var *varp = ncp->vars.value[i]; if (!IS_RECVAR(varp)) continue; diff --git a/src/drivers/ncmpio/ncmpio_filetype.c b/src/drivers/ncmpio/ncmpio_filetype.c index 4a1090d52..8a7e46d8b 100644 --- a/src/drivers/ncmpio/ncmpio_filetype.c +++ b/src/drivers/ncmpio/ncmpio_filetype.c @@ -126,7 +126,7 @@ type_create_subarray64(int ndims, #ifdef HAVE_MPI_LARGE_COUNT MPI_Count *sizes, *subsizes, *starts; - sizes = (MPI_Count*) NCI_Malloc((size_t)ndims * 3 * sizeof(MPI_Count)); + sizes = (MPI_Count*) NCI_Malloc(sizeof(MPI_Count) * ndims * 3); subsizes = sizes + ndims; starts = subsizes + ndims; for (i=0; i 2^31-1, we can safely use * MPI_Type_create_subarray */ - sizes = (int*) NCI_Malloc((size_t)ndims * 3 * SIZEOF_INT); + sizes = (int*) NCI_Malloc(sizeof(int) * ndims * 3); subsizes = sizes + ndims; starts = subsizes + ndims; for (i=0; ivars.ndefined + ncp->vars.num_rec_vars * nrecs); - count = (MPI_Offset*) NCI_Malloc(nsegs * SIZEOF_MPI_OFFSET); + count = (MPI_Offset*) NCI_Malloc(sizeof(MPI_Offset) * nsegs); #ifdef HAVE_MPI_LARGE_COUNT - offset = (MPI_Count*) NCI_Malloc(nsegs * sizeof(MPI_Count)); + offset = (MPI_Count*) NCI_Malloc(sizeof(MPI_Count) * nsegs); #else - offset = (MPI_Aint*) NCI_Malloc(nsegs * SIZEOF_MPI_AINT); + offset = (MPI_Aint*) NCI_Malloc(sizeof(MPI_Aint) * nsegs); #endif /* calculate each segment's offset and count */ @@ -513,9 +513,9 @@ fillerup_aggregate(NC *ncp, NC *old_ncp) /* allocate one contiguous buffer space for all writes */ #ifdef HAVE_MPI_LARGE_COUNT - blocklengths = (MPI_Count*) NCI_Malloc((size_t)j * sizeof(MPI_Count)); + blocklengths = (MPI_Count*) NCI_Malloc(sizeof(MPI_Count) * j); #else - blocklengths = (int*) NCI_Malloc((size_t)j * SIZEOF_INT); + blocklengths = (int*) NCI_Malloc(sizeof(int) * j); #endif buf = NCI_Malloc((size_t)buf_len); buf_ptr = (char*)buf; diff --git a/src/drivers/ncmpio/ncmpio_i_varn.m4 b/src/drivers/ncmpio/ncmpio_i_varn.m4 index 0d08666b1..be9af9752 100644 --- a/src/drivers/ncmpio/ncmpio_i_varn.m4 +++ b/src/drivers/ncmpio/ncmpio_i_varn.m4 @@ -75,7 +75,7 @@ igetput_varn(NC *ncp, /* validity of starts and counts has been checked at dispatcher layer */ /* calculate nelems and the number of new non-lead and non-zero requests */ - req_nelems = (MPI_Offset*) NCI_Malloc(num * SIZEOF_MPI_OFFSET); + req_nelems = (MPI_Offset*) NCI_Malloc(sizeof(MPI_Offset) * num); new_nreqs = 0; nelems = 0; if (counts != NULL) { @@ -161,7 +161,7 @@ igetput_varn(NC *ncp, /* for nonblocking API, return now if request size is zero */ if (nbytes == 0) goto fn_exit; - memChunk = varp->ndims * SIZEOF_MPI_OFFSET; + memChunk = sizeof(MPI_Offset) * varp->ndims; /* check if type conversion and Endianness byte swap is needed */ need_convert = ncmpii_need_convert(ncp->format, varp->xtype, itype); diff --git a/src/drivers/ncmpio/ncmpio_subfile.c b/src/drivers/ncmpio/ncmpio_subfile.c index 3ea09bb7a..8ed72fba3 100644 --- a/src/drivers/ncmpio/ncmpio_subfile.c +++ b/src/drivers/ncmpio/ncmpio_subfile.c @@ -394,8 +394,8 @@ int ncmpio_subfile_partition(NC *ncp) } /* for each dim */ /* master file: replace the original var with scalar var */ - vpp[i]->dimids_org = (int*) NCI_Malloc((size_t)vpp[i]->ndims * SIZEOF_INT); - memcpy(vpp[i]->dimids_org, vpp[i]->dimids, (size_t)vpp[i]->ndims*SIZEOF_INT); + vpp[i]->dimids_org = (int*) NCI_Malloc(sizeof(int) * vpp[i]->ndims); + memcpy(vpp[i]->dimids_org, vpp[i]->dimids, sizeof(int) * vpp[i]->ndims); vpp[i]->ndims_org = vpp[i]->ndims; vpp[i]->ndims = 0; if (IS_RECVAR(vpp[i])) { @@ -509,10 +509,10 @@ ncmpio_subfile_getput_vars(NC *ncp, &color, MPI_INT); if (status != NC_NOERR) DEBUG_RETURN_ERROR(status) - count_my_req_per_proc = (int *)NCI_Calloc((size_t)nprocs, SIZEOF_INT); - count_others_req_per_proc = (int *)NCI_Calloc((size_t)nprocs, SIZEOF_INT); - buf_count_my = (MPI_Offset *)NCI_Calloc((size_t)nprocs, SIZEOF_MPI_OFFSET); - buf_count_others = (MPI_Offset *)NCI_Calloc((size_t)nprocs, SIZEOF_MPI_OFFSET); + count_my_req_per_proc = (int *)NCI_Calloc((size_t)nprocs, sizeof(int)); + count_others_req_per_proc = (int *)NCI_Calloc((size_t)nprocs, sizeof(int)); + buf_count_my = (MPI_Offset *)NCI_Calloc((size_t)nprocs, sizeof(MPI_Offset)); + buf_count_others = (MPI_Offset *)NCI_Calloc((size_t)nprocs, sizeof(MPI_Offset)); /* TODO: shouldn't it be initialized to 0? */ for (i=0; icomm, &requests[j++]); - statuses = (MPI_Status *)NCI_Malloc((size_t)j*sizeof(MPI_Status)); + statuses = (MPI_Status *)NCI_Malloc(sizeof(MPI_Status) * j); TRACE_COMM(MPI_Waitall)(j, requests, statuses); #ifdef TAU_SSON TAU_PHASE_STOP(t52); @@ -907,7 +907,7 @@ ncmpio_subfile_getput_vars(NC *ncp, NCI_Free(requests); j = 0; - requests = (MPI_Request *)NCI_Malloc((size_t)nprocs*2*sizeof(MPI_Request)); + requests = (MPI_Request *)NCI_Malloc(sizeof(MPI_Request) * nprocs * 2); #ifdef TAU_SSON TAU_PHASE_CREATE_STATIC(t53, "SSON --- getput_vars: exch start,count,", "", TAU_USER); @@ -916,7 +916,7 @@ ncmpio_subfile_getput_vars(NC *ncp, /* when dest rank == myrank */ if (count_others_req_per_proc[myrank] > 0) memcpy(others_req[myrank].start, my_req[myrank].start, - (size_t)ndims_org * 3 * SIZEOF_MPI_OFFSET); + sizeof(MPI_Offset) * ndims_org * 3); /* exchange my_req's and others_req's start[], count[], and start_org[] */ for (i=0; icomm, &requests[j++]); } - statuses = (MPI_Status *)NCI_Malloc((size_t)j*sizeof(MPI_Status)); + statuses = (MPI_Status *)NCI_Malloc(sizeof(MPI_Status) * j); TRACE_COMM(MPI_Waitall)(j, requests, statuses); NCI_Free(statuses); NCI_Free(requests); @@ -973,7 +973,7 @@ ncmpio_subfile_getput_vars(NC *ncp, #endif j = 0; - requests = (MPI_Request *)NCI_Malloc((size_t)nprocs*2*sizeof(MPI_Request)); + requests = (MPI_Request *)NCI_Malloc(sizeof(MPI_Request) * nprocs * 2); xbuf = (void**)NCI_Calloc((size_t)nprocs, sizeof(void *)); @@ -1036,7 +1036,7 @@ ncmpio_subfile_getput_vars(NC *ncp, } /* end if() */ } /* end for() */ - statuses = (MPI_Status *)NCI_Malloc((size_t)j * sizeof(MPI_Status)); + statuses = (MPI_Status *)NCI_Malloc(sizeof(MPI_Status) * j); TRACE_COMM(MPI_Waitall)(j, requests, statuses); NCI_Free(statuses); NCI_Free(requests); @@ -1083,7 +1083,7 @@ ncmpio_subfile_getput_vars(NC *ncp, double stime, wait_time; stime = MPI_Wtime(); */ - array_of_statuses = (int *)NCI_Malloc((size_t)nasyncios * SIZEOF_INT); + array_of_statuses = (int *)NCI_Malloc(sizeof(int) * nasyncios); status = ncmpio_wait(ncp->ncp_sf, nasyncios, array_of_requests, array_of_statuses, NC_REQ_COLL); if (status != NC_NOERR) DEBUG_RETURN_ERROR(status) NCI_Free(array_of_statuses); diff --git a/src/drivers/ncmpio/ncmpio_util.c b/src/drivers/ncmpio/ncmpio_util.c index fb522f0e1..7124c424a 100644 --- a/src/drivers/ncmpio/ncmpio_util.c +++ b/src/drivers/ncmpio/ncmpio_util.c @@ -64,7 +64,7 @@ void ncmpio_set_pnetcdf_hints(NC *ncp, /* Hint nc_header_align_size is now deprecated. But for backward * compatibility, let's still check. */ - int info_h_align = -1; + MPI_Offset info_h_align = -1; MPI_Info_get(user_info, "nc_header_align_size", MPI_MAX_INFO_VAL-1, value, &flag); if (flag) { @@ -348,7 +348,7 @@ ncmpio_last_offset(const NC *ncp, /* when count == NULL, this is called from a var API */ if (count != NULL) { - last_indx = (MPI_Offset*) NCI_Malloc((size_t)ndims * SIZEOF_MPI_OFFSET); + last_indx = (MPI_Offset*) NCI_Malloc(sizeof(MPI_Offset) * ndims); if (stride != NULL) { for (i=0; i 0) { - varp->shape = (MPI_Offset*)NCI_Calloc(ndims, SIZEOF_MPI_OFFSET); - varp->dsizes = (MPI_Offset*)NCI_Calloc(ndims, SIZEOF_MPI_OFFSET); - varp->dimids = (int *) NCI_Calloc(ndims, SIZEOF_INT); + varp->shape = (MPI_Offset*)NCI_Calloc(ndims, sizeof(MPI_Offset)); + varp->dsizes = (MPI_Offset*)NCI_Calloc(ndims, sizeof(MPI_Offset)); + varp->dimids = (int *) NCI_Calloc(ndims, sizeof(int)); } varp->name = name; /* name has been malloc-ed */ @@ -94,7 +94,7 @@ dup_NC_var(const NC_var *rvarp, int attr_hsize) /* copy dimids[] */ if (rvarp->ndims != 0 && rvarp->dimids != NULL) - memcpy(varp->dimids, rvarp->dimids, (size_t)rvarp->ndims * SIZEOF_INT); + memcpy(varp->dimids, rvarp->dimids, sizeof(int) * rvarp->ndims); #ifndef SEARCH_NAME_LINEARLY /* initialize hashing lookup table size for attributes */ @@ -112,8 +112,8 @@ dup_NC_var(const NC_var *rvarp, int attr_hsize) * compute_var_shape() to recompute it after a new variable is created */ if (rvarp->ndims > 0) { /* skip memcpy if ndims == 0 (scalar variables) */ - memcpy(varp->shape, rvarp->shape, (size_t)rvarp->ndims * SIZEOF_MPI_OFFSET); - memcpy(varp->dsizes, rvarp->dsizes, (size_t)rvarp->ndims * SIZEOF_MPI_OFFSET); + memcpy(varp->shape, rvarp->shape, sizeof(MPI_Offset) * rvarp->ndims); + memcpy(varp->dsizes, rvarp->dsizes, sizeof(MPI_Offset) * rvarp->ndims); } varp->xsz = rvarp->xsz; varp->len = rvarp->len; @@ -384,7 +384,7 @@ ncmpio_def_var(void *ncdp, /* copy dimids[] */ if (ndims != 0 && dimids != NULL) - memcpy(varp->dimids, dimids, (size_t)ndims * SIZEOF_INT); + memcpy(varp->dimids, dimids, sizeof(int) * ndims); /* set up array dimensional structures */ err = ncmpio_NC_var_shape64(varp, &ncp->dims); @@ -536,11 +536,11 @@ ncmpio_inq_var(void *ncdp, #ifdef ENABLE_SUBFILING /* varp->dimids_org is already set during open or enddef */ if (varp->num_subfiles > 1 && varp->ndims_org > 0) - memcpy(dimids, varp->dimids_org, (size_t)varp->ndims_org * SIZEOF_INT); + memcpy(dimids, varp->dimids_org, sizeof(int) * varp->ndims_org); else #endif if (varp->ndims > 0) - memcpy(dimids, varp->dimids, (size_t)varp->ndims * SIZEOF_INT); + memcpy(dimids, varp->dimids, sizeof(int) * varp->ndims); } if (nattsp != NULL) *nattsp = varp->attrs.ndefined; diff --git a/src/drivers/ncmpio/ncmpio_wait.c b/src/drivers/ncmpio/ncmpio_wait.c index 9df020f35..a4b2b7f3e 100644 --- a/src/drivers/ncmpio/ncmpio_wait.c +++ b/src/drivers/ncmpio/ncmpio_wait.c @@ -354,7 +354,7 @@ construct_filetypes(NC *ncp, } /* hereinafter, num_reqs > 0 */ - ftypes = (MPI_Datatype*) NCI_Malloc((size_t)num_reqs * sizeof(MPI_Datatype)); + ftypes = (MPI_Datatype*) NCI_Malloc(sizeof(MPI_Datatype) * num_reqs); /* create a filetype for each request */ last_contig_req = -1; /* index of the last contiguous request */ @@ -777,9 +777,9 @@ extract_reqs(NC *ncp, /* allocate put_list and get_list */ if (*num_w_reqs) - *put_list = (NC_req*) NCI_Malloc((*num_w_reqs)*sizeof(NC_req)); + *put_list = (NC_req*) NCI_Malloc(sizeof(NC_req) * (*num_w_reqs)); if (*num_r_reqs) - *get_list = (NC_req*) NCI_Malloc((*num_r_reqs)*sizeof(NC_req)); + *get_list = (NC_req*) NCI_Malloc(sizeof(NC_req) * (*num_r_reqs)); /* copy over ncp->put_list and ncp->get_list to *put_list and *get_list */ put_list_ptr = *put_list; @@ -1291,7 +1291,7 @@ vars_flatten(int ndim, /* number of dimensions */ } if (stride == NULL) { /* equivalent to {1, 1, ..., 1} */ - stride = (MPI_Offset*) NCI_Malloc((size_t)ndim * SIZEOF_MPI_OFFSET); + stride = (MPI_Offset*) NCI_Malloc(sizeof(MPI_Offset) * ndim); for (i=0; i NC_MAX_INT) { @@ -1667,8 +1667,8 @@ type_create_off_len(MPI_Offset nsegs, /* no. off-len pairs */ buf_type); #else if (true_nsegs < j + 1) { - blocklens = (int*) NCI_Realloc(blocklens, (j+1) * SIZEOF_INT); - disps = (MPI_Aint*) NCI_Realloc(disps, (j+1) * SIZEOF_MPI_AINT); + blocklens = (int*) NCI_Realloc(blocklens, sizeof(int) * (j+1)); + disps = (MPI_Aint*) NCI_Realloc(disps, sizeof(MPI_Aint) * (j+1)); } /* coalesce segs[].off and len to disps[] and blocklens[] */ @@ -1813,7 +1813,7 @@ req_aggregation(NC *ncp, } } - group_index = (int*) NCI_Malloc((size_t)(ngroups+1) * 2 * SIZEOF_INT); + group_index = (int*) NCI_Malloc(sizeof(int) * (ngroups+1) * 2); group_type = group_index + (ngroups+1); /* calculate the starting index of each group and determine group type */ @@ -1863,7 +1863,7 @@ req_aggregation(NC *ncp, * Then use one collective I/O to commit. */ - ftypes = (MPI_Datatype*) NCI_Malloc((size_t)ngroups*2*sizeof(MPI_Datatype)); + ftypes = (MPI_Datatype*) NCI_Malloc(sizeof(MPI_Datatype) * ngroups * 2); btypes = ftypes + ngroups; /* temp buffers, used by multiple calls to construct_filetypes() */ @@ -2311,8 +2311,8 @@ mgetput(NC *ncp, #else int *blocklens; MPI_Aint *disps; - blocklens = (int*) NCI_Malloc((size_t)num_reqs * SIZEOF_INT); - disps = (MPI_Aint*) NCI_Malloc((size_t)num_reqs * SIZEOF_MPI_AINT); + blocklens = (int*) NCI_Malloc(sizeof(int) * num_reqs); + disps = (MPI_Aint*) NCI_Malloc(sizeof(MPI_Aint) * num_reqs); #endif lead_list = (rw_flag == NC_REQ_RD) ? ncp->get_lead_list diff --git a/src/utils/ncmpidiff/cdfdiff.c b/src/utils/ncmpidiff/cdfdiff.c index 206cbcfb0..be19bc0c7 100644 --- a/src/utils/ncmpidiff/cdfdiff.c +++ b/src/utils/ncmpidiff/cdfdiff.c @@ -1035,7 +1035,7 @@ int main(int argc, char **argv) break; pos = ((long long)m + k * nChunks) / var[0]->xsz; - diffStart = (long long*) malloc(var[0]->ndims * sizeof(long long)); + diffStart = (long long*) malloc(sizeof(long long) * var[0]->ndims); for (_i=var[0]->ndims-1; _i>=0; _i--) { if (isRecVar[0] && _i == 0) { diffStart[_i] = r; /* r-th record */ @@ -1092,7 +1092,7 @@ int main(int argc, char **argv) } else { int _i; long long pos, *diffStart; - diffStart = (long long*) malloc(ndims[0] * sizeof(long long)); + diffStart = (long long*) malloc(sizeof(long long) * ndims[0]); if (worst != -1) pos = worst; for (_i=ndims[0]-1; _i>=0; _i--) { long long dimLen = var[0]->shape[_i]; diff --git a/src/utils/ncmpidiff/ncmpidiff.c b/src/utils/ncmpidiff/ncmpidiff.c index 8fb5d4f83..c5b8c7eda 100644 --- a/src/utils/ncmpidiff/ncmpidiff.c +++ b/src/utils/ncmpidiff/ncmpidiff.c @@ -225,7 +225,7 @@ } else { \ int _i; \ MPI_Offset *diffStart; \ - diffStart = (MPI_Offset*) malloc(ndims[0] * sizeof(MPI_Offset)); \ + diffStart = (MPI_Offset*) malloc(sizeof(MPI_Offset) * ndims[0]); \ if (worst != -1) pos = worst; \ v1 = b1[pos]; \ v2 = b2[pos]; \ @@ -669,7 +669,7 @@ int main(int argc, char **argv) varid[0] = i; err = ncmpi_inq_varndims(ncid[0], i, &ndims[0]); HANDLE_ERROR - dimids[0] = (int*) calloc((size_t)ndims[0], SIZEOF_INT); + dimids[0] = (int*) calloc((size_t)ndims[0], sizeof(int)); if (!dimids[0]) OOM_ERROR err = ncmpi_inq_var(ncid[0], i, name[0], &xtype[0], &ndims[0], dimids[0], &natts[0]); HANDLE_ERROR @@ -686,7 +686,7 @@ int main(int argc, char **argv) /* inquire variable metadata for varid[1] */ err = ncmpi_inq_varndims(ncid[1], varid[1], &ndims[1]); HANDLE_ERROR - dimids[1] = (int*) calloc((size_t)ndims[1], SIZEOF_INT); + dimids[1] = (int*) calloc((size_t)ndims[1], sizeof(int)); if (!dimids[1]) OOM_ERROR err = ncmpi_inq_var(ncid[1], varid[1], name[1], &xtype[1], &ndims[1], dimids[1], &natts[1]); HANDLE_ERROR @@ -901,12 +901,12 @@ int main(int argc, char **argv) */ err = ncmpi_inq_varndims(ncid[0], varid1, &ndims[0]); HANDLE_ERROR - dimids[0] = (int*) calloc((size_t)ndims[0], SIZEOF_INT); + dimids[0] = (int*) calloc((size_t)ndims[0], sizeof(int)); if (!dimids[0]) OOM_ERROR err = ncmpi_inq_var(ncid[0], varid1, name[0], &xtype[0], &ndims[0], dimids[0], &natts[0]); HANDLE_ERROR err = ncmpi_inq_varndims(ncid[1], varid2, &ndims[1]); HANDLE_ERROR - dimids[1] = (int*) calloc((size_t)ndims[1], SIZEOF_INT); + dimids[1] = (int*) calloc((size_t)ndims[1], sizeof(int)); if (!dimids[1]) OOM_ERROR err = ncmpi_inq_var(ncid[1], varid2, name[1], &xtype[1], &ndims[1], dimids[1], &natts[1]); HANDLE_ERROR @@ -941,7 +941,7 @@ int main(int argc, char **argv) else if (!check_header && !rank && verbose) printf("\tSAME: number of dimensions (%d)\n",ndims[0]); - shape = (MPI_Offset*) calloc((size_t)ndims[0] * 2, SIZEOF_MPI_OFFSET); + shape = (MPI_Offset*) calloc((size_t)ndims[0] * 2, sizeof(MPI_Offset)); if (!shape) OOM_ERROR start = shape + ndims[0]; diff --git a/src/utils/ncmpidump/ncmpidump.c b/src/utils/ncmpidump/ncmpidump.c index 8a97e780a..be3d72482 100644 --- a/src/utils/ncmpidump/ncmpidump.c +++ b/src/utils/ncmpidump/ncmpidump.c @@ -114,7 +114,7 @@ name_path(const char *path) else /* skip delimeter */ cp++; - new = (char *) malloc((unsigned) (strlen(cp)+1)); + new = (char *) malloc(strlen(cp) + 1); if (new == 0) error("out of memory!"); strcpy(new, cp); /* copy last component of path */ @@ -344,7 +344,7 @@ pr_att(int ncid, free(att.string); break; default: - att.vals = (double *) malloc(att.len * sizeof(double)); + att.vals = (double *) malloc(sizeof(double) * att.len); if (!att.vals) { error("Out of memory!"); NC_CHECK( ncmpi_close(ncid) ); @@ -460,7 +460,7 @@ do_ncdump(const char *path, struct fspec* specp) /* print dimension info */ if (ndims > 0) Printf ("dimensions:\n"); - dims = (struct ncdim*) malloc(ndims*sizeof(struct ncdim)); + dims = (struct ncdim*) malloc(sizeof(struct ncdim) * ndims); for (dimid = 0; dimid < ndims; dimid++) { NC_CHECK(ncmpi_inq_dim(ncid, dimid, dims[dimid].name, &dims[dimid].size) ); @@ -532,7 +532,7 @@ do_ncdump(const char *path, struct fspec* specp) if (var.ndims == 0 || var.dims[0] != xdimid || dims[xdimid].size != 0) { /* Collect variable's dim sizes */ - vdims = (size_t*) malloc(var.ndims * sizeof(size_t)); + vdims = (size_t*) malloc(sizeof(size_t) * var.ndims); for (id = 0; id < var.ndims; id++) vdims[id] = dims[var.dims[id]].size; @@ -623,7 +623,7 @@ make_lvars(char *optarg, struct fspec* fspecp) if (*cp == ',') nvars++; - fspecp->lvars = (char **) malloc(nvars * sizeof(char*)); + fspecp->lvars = (char **) malloc(sizeof(char*) * nvars); if (!fspecp->lvars) error("out of memory"); cpp = fspecp->lvars; diff --git a/src/utils/ncmpidump/vardata.c b/src/utils/ncmpidump/vardata.c index caa4cf001..836231153 100644 --- a/src/utils/ncmpidump/vardata.c +++ b/src/utils/ncmpidump/vardata.c @@ -574,9 +574,9 @@ vardata( initeps = 1; } - cor = (MPI_Offset*) malloc(vrank * sizeof (MPI_Offset)); - edg = (MPI_Offset*) malloc(vrank * sizeof (MPI_Offset)); - add = (size_t*) malloc(vrank * sizeof (size_t)); + cor = (MPI_Offset*) malloc(sizeof(MPI_Offset) * vrank); + edg = (MPI_Offset*) malloc(sizeof(MPI_Offset) * vrank); + add = (size_t*) malloc(sizeof(size_t) * vrank); nels = 1; for (id = 0; id < vrank; id++) { diff --git a/src/utils/ncmpigen/genlib.c b/src/utils/ncmpigen/genlib.c index 072f44852..1e558a92f 100644 --- a/src/utils/ncmpigen/genlib.c +++ b/src/utils/ncmpigen/genlib.c @@ -1265,7 +1265,7 @@ fstrstr( free(istr0); return ostr; } - ostr = cp = (char *) emalloc(12*ilen); + ostr = cp = (char *) emalloc(ilen*12); *ostr = '\0'; if (isprint(*istr)) { /* handle first character in input */ *cp++ = '\''; @@ -1834,7 +1834,7 @@ grow_iarray( int **arpp) /* address of start of int array */ { if (nar == 0) { - *arpp = (int *) emalloc(1 * sizeof(int)); + *arpp = (int *) emalloc(sizeof(int)); return; } if (! pow2(nar)) /* return unless nar is a power of two */ @@ -1860,7 +1860,7 @@ grow_varray( struct vars **arpp) /* address of start of var array */ { if (nar == 0) { - *arpp = (struct vars *) emalloc(1 * sizeof(struct vars)); + *arpp = (struct vars *) emalloc(sizeof(struct vars)); return; } if (! pow2(nar)) /* return unless nar is a power of two */ @@ -1886,7 +1886,7 @@ grow_darray( struct dims **arpp) /* address of start of var array */ { if (nar == 0) { - *arpp = (struct dims *) emalloc(1 * sizeof(struct dims)); + *arpp = (struct dims *) emalloc(sizeof(struct dims)); return; } if (! pow2(nar)) /* return unless nar is a power of two */ @@ -1912,7 +1912,7 @@ grow_aarray( struct atts **arpp) /* address of start of var array */ { if (nar == 0) { - *arpp = (struct atts *) emalloc(1 * sizeof(struct atts)); + *arpp = (struct atts *) emalloc(sizeof(struct atts)); return; } if (! pow2(nar)) /* return unless nar is a power of two */ diff --git a/src/utils/ncmpigen/load.c b/src/utils/ncmpigen/load.c index d8b9a241b..69fe54e3a 100644 --- a/src/utils/ncmpigen/load.c +++ b/src/utils/ncmpigen/load.c @@ -657,7 +657,7 @@ load_netcdf(void *rec_start) break; } - start = (MPI_Offset*) malloc(vars[varnum].ndims * 2 * sizeof(MPI_Offset)); + start = (MPI_Offset*) malloc(sizeof(MPI_Offset) * vars[varnum].ndims * 2); count = start + vars[varnum].ndims; if (vars[varnum].ndims > 0) { diff --git a/src/utils/ncmpigen/ncmpigen.y b/src/utils/ncmpigen/ncmpigen.y index 9efaf9175..4516414b0 100644 --- a/src/utils/ncmpigen/ncmpigen.y +++ b/src/utils/ncmpigen/ncmpigen.y @@ -471,7 +471,7 @@ datadecl: avar exit(9); } rec_len = var_len; - rec_start = malloc ((MPI_Offset)(rec_len*var_size)); + rec_start = malloc((size_t)(rec_len*var_size)); if (rec_start == 0) { derror ("out of memory\n"); exit(3); @@ -1284,8 +1284,8 @@ YYSTYPE install( /* install sname in symbol table */ { YYSTYPE sp; - sp = (YYSTYPE) emalloc (sizeof (struct Symbol)); - sp -> name = (char *) emalloc (strlen (sname) + 1);/* +1 for '\0' */ + sp = (YYSTYPE) emalloc(sizeof(struct Symbol)); + sp -> name = (char *) emalloc(strlen(sname) + 1);/* +1 for '\0' */ (void) strcpy (sp -> name, sname); sp -> next = symlist; /* put at front of list */ sp -> is_dim = 0; diff --git a/src/utils/ncmpigen/ncmpigentab.c b/src/utils/ncmpigen/ncmpigentab.c index c2bd12e8e..117e7d494 100644 --- a/src/utils/ncmpigen/ncmpigentab.c +++ b/src/utils/ncmpigen/ncmpigentab.c @@ -546,8 +546,8 @@ YYSTYPE install( /* install sname in symbol table */ { YYSTYPE sp; - sp = (YYSTYPE) emalloc (sizeof (struct Symbol)); - sp -> name = (char *) emalloc (strlen (sname) + 1);/* +1 for '\0' */ + sp = (YYSTYPE) emalloc(sizeof(struct Symbol)); + sp -> name = (char *) emalloc(strlen(sname) + 1);/* +1 for '\0' */ (void) strcpy (sp -> name, sname); sp -> next = symlist; /* put at front of list */ sp -> is_dim = 0; @@ -594,16 +594,16 @@ static int yygrowstack(void) i = yyssp - yyss; newss = (yyss != 0) - ? (short *)realloc(yyss, newsize * sizeof(*newss)) - : (short *)malloc(newsize * sizeof(*newss)); + ? (short *)realloc(yyss, sizeof(*newss) * newsize) + : (short *)malloc(sizeof(*newss) * newsize); if (newss == 0) return -1; yyss = newss; yyssp = newss + i; newvs = (yyvs != 0) - ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs)) - : (YYSTYPE *)malloc(newsize * sizeof(*newvs)); + ? (YYSTYPE *)realloc(yyvs, sizeof(*newvs) * newsize) + : (YYSTYPE *)malloc(sizeof(*newvs) * newsize); if (newvs == 0) return -1; @@ -1123,7 +1123,7 @@ case 75: exit(9); } rec_len = var_len; - rec_start = malloc ((MPI_Offset)(rec_len*var_size)); + rec_start = malloc((size_t)(rec_len*var_size)); if (rec_start == 0) { derror ("out of memory\n"); exit(3); diff --git a/src/utils/ncoffsets/ncoffsets.c b/src/utils/ncoffsets/ncoffsets.c index 0f003d5f4..977f199dd 100644 --- a/src/utils/ncoffsets/ncoffsets.c +++ b/src/utils/ncoffsets/ncoffsets.c @@ -1114,7 +1114,7 @@ hdr_get_NC_dimarray(bufferinfo *gbp, } else { if (type != NC_DIMENSION) DEBUG_RETURN_ERROR(NC_ENOTNC); - ncap->value = (NC_dim **) malloc(ndefined * sizeof(NC_dim*)); + ncap->value = (NC_dim **) malloc(sizeof(NC_dim*) * ndefined); MALLOC_CHECK(ncap->value) ncap->nalloc = (int)ndefined; @@ -1389,7 +1389,7 @@ hdr_get_NC_attrarray(bufferinfo *gbp, if (type != NC_ATTRIBUTE) DEBUG_RETURN_ERROR(NC_ENOTNC); - ncap->value = (NC_attr **)malloc((size_t)ndefined * sizeof(NC_attr*)); + ncap->value = (NC_attr **)malloc(sizeof(NC_attr*) * ndefined); MALLOC_CHECK(ncap->value) ncap->nalloc = (int)ndefined; @@ -1617,7 +1617,7 @@ hdr_get_NC_vararray(bufferinfo *gbp, if (type != NC_VARIABLE) DEBUG_RETURN_ERROR(NC_ENOTNC); - ncap->value = (NC_var **) malloc((size_t)ndefined * sizeof(NC_var*)); + ncap->value = (NC_var **) malloc(sizeof(NC_var*) * ndefined); MALLOC_CHECK(ncap->value) ncap->nalloc = (int)ndefined; @@ -1814,7 +1814,7 @@ make_lvars(char *optarg, struct fspec* fspecp) if (*cp == ',') nvars++; - fspecp->lvars = (char **) malloc(nvars * sizeof(char*)); + fspecp->lvars = (char **) malloc(sizeof(char*) * nvars); MALLOC_CHECK(fspecp->lvars) cpp = fspecp->lvars; @@ -1828,7 +1828,7 @@ make_lvars(char *optarg, struct fspec* fspecp) cpp++; } fspecp->nlvars = nvars; - fspecp->varp = (NC_var**) malloc(nvars * sizeof(NC_var*)); + fspecp->varp = (NC_var**) malloc(sizeof(NC_var*) * nvars); MALLOC_CHECK(fspecp->varp) } @@ -1981,7 +1981,7 @@ int main(int argc, char *argv[]) /* First check if all selected variables can be found in input file. */ if (fspecp->nlvars > 0) { /* print a selected list of variables */ - fspecp->varids = (int*) malloc(fspecp->nlvars * sizeof(int)); + fspecp->varids = (int*) malloc(sizeof(int) * fspecp->nlvars); MALLOC_CHECK(fspecp->varids) for (i=0; inlvars; i++) { for (j=0; jvars.ndefined; j++) { @@ -2033,9 +2033,9 @@ int main(int argc, char *argv[]) } if (fspecp->nlvars == 0) { /* print all variables */ - fspecp->varp = (NC_var**) malloc(ncp->vars.ndefined * sizeof(NC_var*)); + fspecp->varp = (NC_var**) malloc(sizeof(NC_var*) * ncp->vars.ndefined); MALLOC_CHECK(fspecp->varp) - fspecp->varids = (int*) malloc(ncp->vars.ndefined * sizeof(int)); + fspecp->varids = (int*) malloc(sizeof(int) * ncp->vars.ndefined); MALLOC_CHECK(fspecp->varids) fspecp->nlvars = ncp->vars.ndefined; fspecp->lvars = NULL; diff --git a/src/utils/ncvalidator/ncvalidator.c b/src/utils/ncvalidator/ncvalidator.c index d7ef9a59a..da58bcf6c 100644 --- a/src/utils/ncvalidator/ncvalidator.c +++ b/src/utils/ncvalidator/ncvalidator.c @@ -2111,7 +2111,7 @@ val_NC_check_voff(NC *ncp) if (num_fix_vars == 0) goto check_rec_var; /* check non-record variables first */ - var_off_len = (off_len*) malloc(num_fix_vars * sizeof(off_len)); + var_off_len = (off_len*) malloc(sizeof(off_len) * num_fix_vars); for (i=0, j=0; ivars.ndefined; i++) { NC_var *varp = ncp->vars.value[i]; if (varp->begin < ncp->begin_var) { @@ -2166,7 +2166,7 @@ val_NC_check_voff(NC *ncp) if (ncp->vars.num_rec_vars == 0) return status; /* check record variables */ - var_off_len = (off_len*) malloc(ncp->vars.num_rec_vars * sizeof(off_len)); + var_off_len = (off_len*) malloc(sizeof(off_len) * ncp->vars.num_rec_vars); for (i=0, j=0; ivars.ndefined; i++) { NC_var *varp = ncp->vars.value[i]; if (!IS_RECVAR(varp)) continue; diff --git a/test/C/pres_temp_4D_rd.c b/test/C/pres_temp_4D_rd.c index a5a4999f3..bcc9b71c0 100644 --- a/test/C/pres_temp_4D_rd.c +++ b/test/C/pres_temp_4D_rd.c @@ -177,10 +177,10 @@ int main(int argc, char **argv) start[1] = 0; /* allocate read buffers */ - pres_in = (float **)malloc(count[1] * 2 * sizeof(float *)); + pres_in = (float **)malloc(sizeof(float *) * count[1] * 2); temp_in = pres_in + count[1]; if (count[1] > 0) { - pres_in[0] = (float *)malloc(count[1] * 2 * NLAT * NLON * sizeof(float)); + pres_in[0] = (float *)malloc(sizeof(float) * count[1] * 2 * NLAT * NLON); temp_in[0] = pres_in[0] + count[1] * NLAT * NLON; for (i = 1; i < count[1]; i++) { pres_in[i] = pres_in[i - 1] + NLAT * NLON; diff --git a/test/C/pres_temp_4D_wr.c b/test/C/pres_temp_4D_wr.c index 127b65642..d7dbf1a47 100644 --- a/test/C/pres_temp_4D_wr.c +++ b/test/C/pres_temp_4D_wr.c @@ -231,10 +231,10 @@ int main(int argc, char **argv) start[1] = 0; /* allocate write buffers */ - pres_out = (float **)malloc(count[1] * 2 * sizeof(float *)); + pres_out = (float **)malloc(sizeof(float *) * count[1] * 2); temp_out = pres_out + count[1]; if (count[1] > 0) { - pres_out[0] = (float *)malloc(count[1] * 2 * NLAT * NLON * sizeof(float)); + pres_out[0] = (float *)malloc(sizeof(float) * count[1] * 2 * NLAT * NLON); temp_out[0] = pres_out[0] + count[1] * NLAT * NLON; for (i = 1; i < count[1]; i++) { pres_out[i] = pres_out[i - 1] + NLAT * NLON; diff --git a/test/adios/header.c b/test/adios/header.c index cdd12d70a..e9d0c1afe 100644 --- a/test/adios/header.c +++ b/test/adios/header.c @@ -27,7 +27,7 @@ int cmp_int(int *in, int n, char *lbl){ MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &np); - all = malloc(np * sizeof(int)); + all = malloc(sizeof(int) * np); MPI_Gather(&n, 1, MPI_INT, all, 1, MPI_INT, 0, MPI_COMM_WORLD); if (rank == 0) { diff --git a/test/fandc/csnap.c b/test/fandc/csnap.c index fe425b63c..fb39eed98 100644 --- a/test/fandc/csnap.c +++ b/test/fandc/csnap.c @@ -232,10 +232,10 @@ void write_file(char *filename, double *t) { count_2d[0] = locsiz_2d[0]; count_2d[1] = locsiz_2d[1]; - tt = (double*)malloc(locsiz_3d[0]*locsiz_3d[1]*locsiz_3d[2]*sizeof(double)); + tt = (double*)malloc(sizeof(double) * locsiz_3d[0]*locsiz_3d[1]*locsiz_3d[2]); if (has_2d) - smf = (double*)malloc(locsiz_2d[0]*locsiz_2d[1]*sizeof(double)); + smf = (double*)malloc(sizeof(double) * locsiz_2d[0]*locsiz_2d[1]); else smf = (double*)malloc(sizeof(double)); @@ -322,14 +322,14 @@ void read_file(char *filename, double *t) { count_2d[0] = locsiz_2d[0]; count_2d[1] = locsiz_2d[1]; - tt = (double*)malloc(locsiz_3d[0]*locsiz_3d[1]*locsiz_3d[2]*sizeof(double)); + tt = (double*)malloc(sizeof(double) * locsiz_3d[0]*locsiz_3d[1]*locsiz_3d[2]); if (has_2d) - smf = (double*)malloc(locsiz_2d[0]*locsiz_2d[1]*sizeof(double)); + smf = (double*)malloc(sizeof(double) * locsiz_2d[0]*locsiz_2d[1]); else smf = (double*)malloc(sizeof(double)); - buf = (double*)malloc(locsiz_3d[0]*locsiz_3d[1]*locsiz_3d[2]*sizeof(double)); + buf = (double*)malloc(sizeof(double) * locsiz_3d[0]*locsiz_3d[1]*locsiz_3d[2]); get_fields(tt, smf); diff --git a/test/largefile/high_dim_var.c b/test/largefile/high_dim_var.c index f9507dc94..a15d6e4c9 100644 --- a/test/largefile/high_dim_var.c +++ b/test/largefile/high_dim_var.c @@ -86,7 +86,7 @@ int main(int argc, char** argv) { nelms = (NRECS > DIMLEN) ? NRECS : DIMLEN; for (i=1; i 0) { - pres_out[0] = (float*) malloc(count[1]*2 * NLAT*NLON * sizeof(float)); + pres_out[0] = (float*) malloc(sizeof(float) * count[1]*2 * NLAT*NLON); temp_out[0] = pres_out[0] + count[1] * NLAT*NLON; for (i=1; i 0) { - pres_in[0] = (float*) malloc(count[1]*2 * NLAT*NLON * sizeof(float)); + pres_in[0] = (float*) malloc(sizeof(float) * count[1]*2 * NLAT*NLON); temp_in[0] = pres_in[0] + count[1] * NLAT*NLON; for (i=1; indims); ERR - vdesc->dims = (int*) malloc(vdesc->ndims * sizeof(int)); + vdesc->dims = (int*) malloc(sizeof(int) * vdesc->ndims); err = ncmpi_inq_var(id, ii, vdesc->mnem, diff --git a/test/nc_test/tst_nofill.c b/test/nc_test/tst_nofill.c index 9c4f8caf9..48e14a07c 100644 --- a/test/nc_test/tst_nofill.c +++ b/test/nc_test/tst_nofill.c @@ -401,7 +401,7 @@ main(int argc, char **argv) char varname2[NC_MAX_NAME]; /* How many values in this variable to compare? */ err = ncmpi_inq_varndims(ncid1, varid, &ndims); ERR - dimids = malloc((ndims + 1) * sizeof(int)); + dimids = malloc(sizeof(int) * (ndims + 1)); if (!dimids) printf("Error in file %s line %d\n",__FILE__,__LINE__); err = ncmpi_inq_vardimid (ncid1, varid, dimids); ERR nvals = 1; @@ -417,9 +417,9 @@ main(int argc, char **argv) if (vtype != NC_CHAR) { /* numeric data, just read in as doubles */ double *data1, *data2; /* Allocate space to hold values in both files */ - data1 = malloc((nvals + 1) * sizeof(double)); + data1 = malloc(sizeof(double) * (nvals + 1)); if (!data1) printf("Error in file %s line %d\n",__FILE__,__LINE__); - data2 = malloc((nvals + 1) * sizeof(double)); + data2 = malloc(sizeof(double) * (nvals + 1)); if (!data2) printf("Error in file %s line %d\n",__FILE__,__LINE__); /* Read in values */ err = ncmpi_get_var_double_all(ncid1, varid, data1); ERR @@ -439,9 +439,9 @@ main(int argc, char **argv) } else { /* character data */ char *data1, *data2; /* Allocate space to hold values in both files */ - data1 = malloc((nvals + 1) * sizeof(char)); + data1 = malloc(sizeof(char) * (nvals + 1)); if (!data1) printf("Error in file %s line %d\n",__FILE__,__LINE__); - data2 = malloc((nvals + 1) * sizeof(char)); + data2 = malloc(sizeof(char) * (nvals + 1)); if (!data2) printf("Error in file %s line %d\n",__FILE__,__LINE__); /* Read in values */ err = ncmpi_get_var_text_all(ncid1, varid, data1); ERR diff --git a/test/nonblocking/bput_varn.m4 b/test/nonblocking/bput_varn.m4 index 67377a071..58cb0daaf 100644 --- a/test/nonblocking/bput_varn.m4 +++ b/test/nonblocking/bput_varn.m4 @@ -165,7 +165,7 @@ static int clear_file_contents_$1(int ncid, int *varid) { int i, err, nerrs=0, rank; - $1 *w_buffer = ($1*) malloc(NY*NX * sizeof($1)); + $1 *w_buffer = ($1*) malloc(sizeof($1) * NY*NX); for (i=0; i 4) MPI_Barrier(MPI_COMM_WORLD); @@ -309,8 +309,8 @@ test_bput_varn_$1(char *filename, int cdf) err = ncmpi_enddef(ncid); CHECK_ERR /* allocate space for starts and counts */ - starts[0] = (MPI_Offset**) malloc(4 * 6 * sizeof(MPI_Offset*)); - counts[0] = (MPI_Offset**) malloc(4 * 6 * sizeof(MPI_Offset*)); + starts[0] = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * 4 * 6); + counts[0] = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * 4 * 6); starts[0][0] = (MPI_Offset*) calloc(4 * 6 * NDIMS, sizeof(MPI_Offset)); counts[0][0] = (MPI_Offset*) calloc(4 * 6 * NDIMS, sizeof(MPI_Offset)); for (i=1; i<4; i++) { @@ -363,7 +363,7 @@ test_bput_varn_$1(char *filename, int cdf) } /* allocate I/O buffer and initialize its contents */ - buffer[i] = ($1*) malloc(req_lens[i] * sizeof($1)); + buffer[i] = ($1*) malloc(sizeof($1) * req_lens[i]); for (j=0; j 4) MPI_Barrier(MPI_COMM_WORLD); @@ -238,8 +238,8 @@ int main(int argc, char** argv) #endif /* allocate space for starts and counts */ - starts[0] = (MPI_Offset**) malloc(4 * 6 * sizeof(MPI_Offset*)); - counts[0] = (MPI_Offset**) malloc(4 * 6 * sizeof(MPI_Offset*)); + starts[0] = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * 4 * 6); + counts[0] = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * 4 * 6); starts[0][0] = (MPI_Offset*) calloc(4 * 6 * NDIMS, sizeof(MPI_Offset)); counts[0][0] = (MPI_Offset*) calloc(4 * 6 * NDIMS, sizeof(MPI_Offset)); for (i=1; i<4; i++) { @@ -289,7 +289,7 @@ int main(int argc, char** argv) } /* allocate I/O buffer and initialize its contents */ - buffer[i] = (long long*) malloc(req_lens[i] * sizeof(long long)); + buffer[i] = (long long*) malloc(sizeof(long long) * req_lens[i]); for (j=0; j0) cbuffer[0] = (long long*) malloc(bufsize * sizeof(long long)); + if (bufsize>0) cbuffer[0] = (long long*) malloc(sizeof(long long) * bufsize); for (i=1; i 4) MPI_Barrier(MPI_COMM_WORLD); @@ -264,8 +264,8 @@ test_varn(int ncid, int rank, int *varid) */ /* allocate space for starts and counts */ - starts[0] = (MPI_Offset**) malloc(4 * 6 * sizeof(MPI_Offset*)); - counts[0] = (MPI_Offset**) malloc(4 * 6 * sizeof(MPI_Offset*)); + starts[0] = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * 4 * 6); + counts[0] = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * 4 * 6); starts[0][0] = (MPI_Offset*) calloc(4 * 6 * NDIMS, sizeof(MPI_Offset)); counts[0][0] = (MPI_Offset*) calloc(4 * 6 * NDIMS, sizeof(MPI_Offset)); for (i=1; i<4; i++) { @@ -318,7 +318,7 @@ test_varn(int ncid, int rank, int *varid) } /* allocate I/O buffer and initialize its contents */ - buffer[i] = (long long*) malloc(req_lens[i] * sizeof(long long)); + buffer[i] = (long long*) malloc(sizeof(long long) * req_lens[i]); for (j=0; j0) { - cbuffer[0] = (long long*) malloc(bufsize * sizeof(long long)); + cbuffer[0] = (long long*) malloc(sizeof(long long) * bufsize); for (i=1; i nprocs) ? nvars : nprocs; - varid = (int *)malloc(nvars2*sizeof(int)); + varid = (int *)malloc(sizeof(int)*nvars2); if (varid == NULL){ printf("varid malloc error\n"); nerrs++; goto fn_exit; diff --git a/test/subfile/test_subfile.c b/test/subfile/test_subfile.c index dbbb9cf6b..0bb6cdd53 100644 --- a/test/subfile/test_subfile.c +++ b/test/subfile/test_subfile.c @@ -114,39 +114,39 @@ int main(int argc, char **argv) array_of_gsizes[0] = array_of_gsizes[1] = array_of_gsizes[2] = length; - buf = (int **)malloc(nvars*sizeof(int*)); + buf = (int **)malloc(sizeof(int*) * nvars); if (buf == NULL){ printf("buf malloc error\n"); nerrs++; goto fn_exit; } - bufcount_list = (MPI_Offset *)malloc(nvars*sizeof(MPI_Offset)); + bufcount_list = (MPI_Offset *)malloc(sizeof(MPI_Offset)*nvars); if (bufcount_list == NULL){ printf("bufcount_list malloc error\n"); nerrs++; goto fn_exit; } - starts_list = (MPI_Offset **)malloc(nvars*sizeof(MPI_Offset *)); + starts_list = (MPI_Offset **)malloc(sizeof(MPI_Offset *)*nvars); if (starts_list== NULL){ printf("starts_list malloc error\n"); nerrs++; goto fn_exit; } - count_list = (MPI_Offset **)malloc(nvars*sizeof(MPI_Offset *)); + count_list = (MPI_Offset **)malloc(sizeof(MPI_Offset *)*nvars); if (count_list == NULL){ printf("count_list malloc error\n"); nerrs++; goto fn_exit; } - datatype_list = (MPI_Datatype*)malloc(nvars*sizeof(MPI_Datatype)); + datatype_list = (MPI_Datatype*)malloc(sizeof(MPI_Datatype)*nvars); if (datatype_list == NULL){ printf("count_list malloc error\n"); nerrs++; goto fn_exit; } for (i=0; i works fine*/ num_reqs = 2; - starts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*)); - counts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*)); + starts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); + counts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); starts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset)); counts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset)); for (i = 1; i < num_reqs; i++) { diff --git a/test/testcases/test_vard.c b/test/testcases/test_vard.c index 9a11288cf..405a5efcc 100644 --- a/test/testcases/test_vard.c +++ b/test/testcases/test_vard.c @@ -91,7 +91,7 @@ int get_var_and_verify(int ncid, int i, j, rank, err, *ncbuf, nerrs=0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - ncbuf = (int *) malloc((count[0]+4)*(count[1]+4)*sizeof(int)); + ncbuf = (int *) malloc(sizeof(int) * (count[0]+4) * (count[1]+4)); /* clear the contents of the read buffer */ for (j=0; jfname, id); /* allocate I/O buffers and initialize their contents */ - ibuf = (int*) malloc(NY * NX * sizeof(int)); - dbuf = (double*) malloc(NY * NX * sizeof(double)); + ibuf = (int*) malloc(sizeof(int) * NY * NX); + dbuf = (double*) malloc(sizeof(double) * NY * NX); for (i=0; i 0) { - starts = (MPI_Offset**) malloc(num_reqs * sizeof(MPI_Offset*)); - counts = (MPI_Offset**) malloc(num_reqs * sizeof(MPI_Offset*)); + starts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); + counts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); starts[0] = (MPI_Offset*) calloc(num_reqs * NDIMS, sizeof(MPI_Offset)); counts[0] = (MPI_Offset*) calloc(num_reqs * NDIMS, sizeof(MPI_Offset)); for (i=1; i 0) { - starts = (MPI_Offset**) malloc(num_reqs * sizeof(MPI_Offset*)); - counts = (MPI_Offset**) malloc(num_reqs * sizeof(MPI_Offset*)); + starts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); + counts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs); starts[0] = (MPI_Offset*) calloc(num_reqs * NDIMS, sizeof(MPI_Offset)); counts[0] = (MPI_Offset*) calloc(num_reqs * NDIMS, sizeof(MPI_Offset)); for (i=1; i