From fc2fc4552ae42729c37d3b67dee423f738e5b09f Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 7 Mar 2019 11:46:08 -0700 Subject: [PATCH] converting to malloc instead of VLAs to move from stack to heap --- src/clib/pioc_sc.c | 13 +++++++++++-- tests/cunit/test_perf2.c | 21 +++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/clib/pioc_sc.c b/src/clib/pioc_sc.c index 6ab5d01b618..0648264eeeb 100644 --- a/src/clib/pioc_sc.c +++ b/src/clib/pioc_sc.c @@ -144,12 +144,18 @@ PIO_Offset GCDblocksize(int arrlen, const PIO_Offset *arr_in) PIO_Offset bsize; /* Size of the block. */ PIO_Offset bsizeg; /* Size of gap block. */ PIO_Offset blklensum; /* Sum of all block lengths. */ - PIO_Offset del_arr[arrlen - 1]; /* Array of deltas between adjacent elements in arr_in. */ - PIO_Offset loc_arr[arrlen - 1]; + PIO_Offset *del_arr; /* Array of deltas between adjacent elements in arr_in. */ + PIO_Offset *loc_arr; /* Check inputs. */ pioassert(arrlen > 0 && arr_in, "invalid input", __FILE__, __LINE__); + /* Allocate arrays. */ + if (!(loc_arr = malloc(sizeof(PIO_Offset) * (arrlen - 1)))) + return PIO_ENOMEM; + if (!(del_arr = malloc(sizeof(PIO_Offset) * (arrlen - 1)))) + return PIO_ENOMEM; + /* Count the number of contiguous blocks in arr_in. If any if these blocks is of size 1, we are done and can return. Otherwise numtimes is the number of blocks. */ @@ -226,6 +232,9 @@ PIO_Offset GCDblocksize(int arrlen, const PIO_Offset *arr_in) bsize = lgcd(bsize, arr_in[0]); } + free(loc_arr); + free(del_arr); + return bsize; } diff --git a/tests/cunit/test_perf2.c b/tests/cunit/test_perf2.c index dd5e7ee4183..883ef5880bb 100644 --- a/tests/cunit/test_perf2.c +++ b/tests/cunit/test_perf2.c @@ -126,9 +126,16 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank PIO_Offset arraylen = EXPECTED_MAPLEN; int int_fillvalue = NC_FILL_INT; void *fillvalue = NULL; - int test_data[arraylen]; - int test_data2[arraylen]; - int test_data_in[arraylen]; + int *test_data; + int *test_data2; + int *test_data_in; + + if (!(test_data = malloc(sizeof(int) * arraylen))) + ERR(PIO_ENOMEM); + if (!(test_data2 = malloc(sizeof(int) * arraylen))) + ERR(PIO_ENOMEM); + if (!(test_data_in = malloc(sizeof(int) * arraylen))) + ERR(PIO_ENOMEM); /* Initialize some data. */ for (int f = 0; f < arraylen; f++) @@ -146,7 +153,8 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank for (int fmt = 0; fmt < num_flavors; fmt++) { /* Create the filename. */ - sprintf(filename, "data_%s_iotype_%d.nc", TEST_NAME, flavor[fmt]); + /* sprintf(filename, "data_%s_iotype_%d.nc", TEST_NAME, flavor[fmt]); */ + sprintf(filename, "data__iotype_.nc"); /* Create the netCDF output file. */ if ((ret = PIOc_createfile(iosysid, &ncid, &flavor[fmt], filename, PIO_CLOBBER))) @@ -223,6 +231,11 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank if ((ret = PIOc_closefile(ncid2))) ERR(ret); } + + free(test_data); + free(test_data2); + free(test_data_in); + return PIO_NOERR; }