Skip to content

Commit

Permalink
Fix several stack/frame size warnings (#537)
Browse files Browse the repository at this point in the history
Converts static 1D arrays to dynamic
  • Loading branch information
derobins authored Feb 15, 2024
1 parent 958a771 commit d243953
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 40 deletions.
12 changes: 11 additions & 1 deletion hdf/test/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

#define HLCONVERT_TAG 1500

static uint8 outbuf[BUFSIZE], inbuf[BUFSIZE];
static uint8 *outbuf = NULL;
static uint8 *inbuf = NULL;

void
test_hblocks(void)
Expand All @@ -32,6 +33,12 @@ test_hblocks(void)
int32 ret;
intn errors = 0;

outbuf = (uint8 *)calloc(BUFSIZE, sizeof(uint8));
inbuf = (uint8 *)calloc(BUFSIZE, sizeof(uint8));

CHECK_ALLOC(outbuf, "outbuf", "test_hblocks");
CHECK_ALLOC(inbuf, "outbuf", "test_hblocks");

for (i = 0; i < BUFSIZE; i++)
outbuf[i] = (uint8)(i % 256);

Expand Down Expand Up @@ -267,5 +274,8 @@ test_hblocks(void)
errors++;
}

free(outbuf);
free(inbuf);

num_errs += errors; /* increment global error count */
}
19 changes: 11 additions & 8 deletions hdf/test/chunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@
* HMCsetMaxCache()
* HMCwriteChunk()
* HMCreadChunk()
*
*
* Author -GeorgeV
*
*/

#include "tproto.h"
Expand All @@ -120,8 +116,8 @@
#define BUFSIZE 12288

/* Some static data buffers */
static uint8 outbuf[BUFSIZE], /* output data buffer */
inbuf[BUFSIZE]; /* input data buffer */
static uint8 *outbuf = NULL;
static uint8 *inbuf = NULL;

/* used to verify data in Test 2. */
static uint8 outbuf_2[16] = {0, 0, 2, 3, 0, 0, 6, 7, 8, 9, 0, 0, 12, 13, 0, 0};
Expand Down Expand Up @@ -163,8 +159,6 @@ static uint8 u8_data[2][3][4] = {{{0, 1, 2, 3}, {10, 11, 12, 13}, {20, 21, 22, 2

/*
* main entry point to tests the Special Chunking layer...
*
* -GeorgeV
*/
void
test_chunks(void)
Expand Down Expand Up @@ -194,6 +188,12 @@ test_chunks(void)
model_info minfo;
intn errors = 0;

outbuf = (uint8 *)calloc(BUFSIZE, sizeof(uint8));
inbuf = (uint8 *)calloc(BUFSIZE, sizeof(uint8));

CHECK_ALLOC(outbuf, "outbuf", "test_chunks");
CHECK_ALLOC(inbuf, "outbuf", "test_chunks");

/* initialize out buffer */
for (i = 0; i < BUFSIZE; i++)
outbuf[i] = (char)(i % 256);
Expand Down Expand Up @@ -2197,5 +2197,8 @@ test_chunks(void)
/* Don't forget to free dimensions allocate for chunk definition */
free(chunk[0].pdims);

free(outbuf);
free(inbuf);

num_errs += errors; /* increment global error count */
} /* test_chunks() */
12 changes: 11 additions & 1 deletion hdf/test/extelt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

#define BUF_SIZE 4096

static uint8 outbuf[BUF_SIZE], inbuf[BUF_SIZE];
static uint8 *outbuf = NULL;
static uint8 *inbuf = NULL;

void
test_hextelt(void)
Expand All @@ -39,6 +40,12 @@ test_hextelt(void)
intn errflag = 0;
intn errors = 0;

outbuf = (uint8 *)calloc(BUF_SIZE, sizeof(uint8));
inbuf = (uint8 *)calloc(BUF_SIZE, sizeof(uint8));

CHECK_ALLOC(outbuf, "outbuf", "test_hextelt");
CHECK_ALLOC(inbuf, "outbuf", "test_hextelt");

/* Initialize buffer */
for (i = 0; i < BUF_SIZE; i++)
outbuf[i] = (char)(i % 256);
Expand Down Expand Up @@ -390,5 +397,8 @@ test_hextelt(void)
ret = HXsetdir(NULL);
CHECK_VOID(ret, FAIL, "HXsetdir");

free(outbuf);
free(inbuf);

num_errs += errors; /* increment global error count */
}
12 changes: 11 additions & 1 deletion hdf/test/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
#define TESTFILE_NAME "t.hdf"
#define BUF_SIZE 4096

static uint8 outbuf[BUF_SIZE], inbuf[BUF_SIZE];
static uint8 *outbuf = NULL;
static uint8 *inbuf = NULL;

void
test_hfile(void)
Expand All @@ -62,6 +63,12 @@ test_hfile(void)
intn errors = 0;
intn ret_bool;

outbuf = (uint8 *)calloc(BUF_SIZE, sizeof(uint8));
inbuf = (uint8 *)calloc(BUF_SIZE, sizeof(uint8));

CHECK_ALLOC(outbuf, "outbuf", "test_hfile");
CHECK_ALLOC(inbuf, "outbuf", "test_hfile");

for (i = 0; i < BUF_SIZE; i++)
outbuf[i] = (char)(i % 256);

Expand Down Expand Up @@ -211,4 +218,7 @@ test_hfile(void)

ret_bool = (intn)Hishdf("qqqqqqqq.qqq"); /* I sure hope it isn't there */
CHECK_VOID(ret, TRUE, "Hishdf");

free(outbuf);
free(inbuf);
}
64 changes: 35 additions & 29 deletions mfhdf/test/hdftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,42 @@ extern int test_att_ann_datainfo();
int
main(void)
{
int32 f1, f2, fnbit; /* File handles */
int32 nt; /* Number type */
int32 dimsize[10]; /* dimension sizes */
int32 newsds, newsds2, newsds3; /* SDS handles */
int32 sdsid; /* SDS handle */
int32 dimid, dimid1, dimid2; /* Dimension handles */
int32 num_sds; /* number of SDS in file */
int32 num_gattr; /* Number of global attributes */
int32 index; /* Index of dataset in file */
int32 ival;
int32 sdid; /* another SDS handle */
int32 rank; /* rank of SDS */
intn status; /* status flag */
intn nattrs; /* Number of attributes again? */
char name[90];
char text[256];
int32 start[10], end[10], stride[10]; /* start, end, stride arrays */
int32 scale[10];
char l[80], u[80], fmt[80], c[80];
int32 count;
int32 fillval = 0, readval = 0;
int32 idata[100];
int32 rdata[100];
int16 sdata[100], outdata[100];
int32 ndg_saved_ref; /* used to save a ref of an SDS in one of the test */
uint8 iuval;
float32 data[1000], max, min, imax, imin;
float64 cal, cale, ioff, ioffe;
int num_errs = 0; /* number of errors so far */
int32 f1, f2, fnbit; /* File handles */
int32 nt; /* Number type */
int32 dimsize[10]; /* dimension sizes */
int32 newsds, newsds2, newsds3; /* SDS handles */
int32 sdsid; /* SDS handle */
int32 dimid, dimid1, dimid2; /* Dimension handles */
int32 num_sds; /* number of SDS in file */
int32 num_gattr; /* Number of global attributes */
int32 index; /* Index of dataset in file */
int32 ival;
int32 sdid; /* another SDS handle */
int32 rank; /* rank of SDS */
intn status; /* status flag */
intn nattrs; /* Number of attributes again? */
char name[90];
char text[256];
int32 start[10], end[10], stride[10]; /* start, end, stride arrays */
int32 scale[10];
char l[80], u[80], fmt[80], c[80];
int32 count;
int32 fillval = 0, readval = 0;
int32 idata[100];
int32 rdata[100];
int16 sdata[100], outdata[100];
int32 ndg_saved_ref; /* used to save a ref of an SDS in one of the test */
uint8 iuval;
float32 *data = NULL;
float32 max, min, imax, imin;
float64 cal, cale, ioff, ioffe;
int num_errs = 0; /* number of errors so far */

ncopts = NC_VERBOSE;

data = (float32 *)calloc(1000, sizeof(float32));
CHECK_ALLOC(data, "data", "main");

/* Testing SDstart */
/* Try start non-existing file with RDONLY and RDWR. Both should fail. */
f1 = SDstart(UFOFILE, DFACC_RDONLY);
Expand Down Expand Up @@ -1336,6 +1340,8 @@ main(void)
/* status = test_sd(); */
/* num_errs = num_errs + status; */

free(data);

if (num_errs == 0) {
printf("*** HDF-SD test passes ***\n");
return EXIT_SUCCESS;
Expand Down

0 comments on commit d243953

Please sign in to comment.