Skip to content

Commit

Permalink
Clean up hrepack code (#708)
Browse files Browse the repository at this point in the history
* Adjust types and cast to remove warnings
* Fix all other warnings
* Remove noise comments
* Move some iterator variables to loop
  • Loading branch information
derobins committed Mar 31, 2024
1 parent f1b34d1 commit 882e76a
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 295 deletions.
25 changes: 0 additions & 25 deletions mfhdf/hrepack/hrepack.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ int list_main(const char *infname, const char *outfname, options_t *options);
*
* Return: FAIL, SUCCEED
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 10, 2003
*
*-------------------------------------------------------------------------
*/
int
Expand Down Expand Up @@ -75,13 +71,8 @@ hrepack_main(const char *infile, const char *outfile, options_t *options)
*
* Return: FAIL, SUCCEED
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 23, 2003
*
*-------------------------------------------------------------------------
*/

int
hrepack_addcomp(const char *str, options_t *options)
{
Expand Down Expand Up @@ -139,13 +130,8 @@ hrepack_addcomp(const char *str, options_t *options)
*
* Return: FAIL, SUCCEED
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 23, 2003
*
*-------------------------------------------------------------------------
*/

int
hrepack_addchunk(const char *str, options_t *options)
{
Expand Down Expand Up @@ -202,7 +188,6 @@ hrepack_addchunk(const char *str, options_t *options)
*
*-------------------------------------------------------------------------
*/

void
hrepack_init(options_t *options, int verbose)
{
Expand All @@ -219,7 +204,6 @@ hrepack_init(options_t *options, int verbose)
*
*-------------------------------------------------------------------------
*/

void
hrepack_end(options_t *options)
{
Expand All @@ -233,10 +217,6 @@ hrepack_end(options_t *options)
*
* Return: FAIL, SUCCEED
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 25, 2003
*
*-------------------------------------------------------------------------
*/
int
Expand Down Expand Up @@ -334,13 +314,8 @@ print_options(options_t *options)
*
* Return: FAIL, SUCCEED
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 30, 2003
*
*-------------------------------------------------------------------------
*/

int
read_info(const char *filename, options_t *options)
{
Expand Down
2 changes: 1 addition & 1 deletion mfhdf/hrepack/hrepack_an.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ copy_an_data(int32 infile_id, int32 outfile_id, int32 ref_in, int32 tag_in, int3
if (is_label)
ann_length++;

if ((buf = (char *)malloc((ann_length) * sizeof(int8))) == NULL) {
if ((buf = (char *)malloc((size_t)ann_length * sizeof(int8))) == NULL) {
printf("Failed to get memory for AN %d of <%s>\n", i, path);
continue;
}
Expand Down
13 changes: 0 additions & 13 deletions mfhdf/hrepack/hrepack_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,8 @@ main(int argc, char **argv)
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: August 3, 2003
*
*-------------------------------------------------------------------------
*/

static int
sds_get_compck(char *fname, char *sds_name)
{
Expand Down Expand Up @@ -152,13 +147,8 @@ sds_get_compck(char *fname, char *sds_name)
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: August 3, 2003
*
*-------------------------------------------------------------------------
*/

static int
sds_get_all(char *fname)
{
Expand Down Expand Up @@ -214,7 +204,6 @@ sds_get_all(char *fname)
*
*-------------------------------------------------------------------------
*/

static const char *
get_scomp(comp_coder_t code)
{
Expand Down Expand Up @@ -247,7 +236,6 @@ get_scomp(comp_coder_t code)
*
*-------------------------------------------------------------------------
*/

static const char *
get_schunk(int32 flags)
{
Expand All @@ -272,7 +260,6 @@ get_schunk(int32 flags)
*
*-------------------------------------------------------------------------
*/

static void
usage(void)
{
Expand Down
88 changes: 21 additions & 67 deletions mfhdf/hrepack/hrepack_dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef struct match_dim_table_t {
/* methods for match_dim_table_t */
static void match_dim_table_free(match_dim_table_t *mdim_tbl);
static void match_dim_table_init(match_dim_table_t **tbl);
static void match_dim_table_add(match_dim_table_t *mdim_tbl, unsigned *flags, char *dim_name, int32 ref);
static void match_dim_table_add(match_dim_table_t *mdim_tbl, int *flags, char *dim_name, int32 ref);

/* generate the SDS */
static int gen_dim(char *name, int32 ref, int32 sd_in, int32 sd_out, options_t *options);
Expand All @@ -58,11 +58,6 @@ static int gen_dim(char *name, int32 ref, int32 sd_in, int32 sd_out, options_t *
* Folk, Michael; Zoellick, Bill. (1992). File Structures. Addison-Wesley.
*
* Return: void
*
* Programmer: Pedro Vicente Nunes, pvn@hdfgroup.org
*
* Date: May 10, 2006
*
*-------------------------------------------------------------------------
*/
void
Expand All @@ -74,7 +69,7 @@ match_dim(int32 sd_in, int32 sd_out, dim_table_t *dt1, dim_table_t *dt2, options
int curr2 = 0;
/*build a common list */
match_dim_table_t *mattbl = NULL;
unsigned inlist[2];
int inlist[2];
int i;

#if defined(HREPACK_DEBUG)
Expand Down Expand Up @@ -181,31 +176,26 @@ match_dim(int32 sd_in, int32 sd_out, dim_table_t *dt1, dim_table_t *dt2, options
* Purpose: generate "lone" dimensions.
*
* Return: -1 error, 1 ok
*
* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
*
* Date: May 10, 2006
*
*-------------------------------------------------------------------------
*/
static int
gen_dim(char *name, /* name of SDS */
int32 ref, /* ref of SDS */
int32 sd_in, int32 sd_out, options_t *options)
{
int32 sds_id, /* data set identifier */
sds_out = FAIL, /* data set identifier */
dim_id, /* dimension identifier */
sds_index, /* index number of the data set */
dtype, /* SDS data type */
dimsizes[H4_MAX_VAR_DIMS], /* dimensions of SDS */
start[H4_MAX_VAR_DIMS], /* read start */
edges[H4_MAX_VAR_DIMS], /* read edges */
nattrs, /* number of SDS attributes */
rank, /* rank of SDS */
numtype, /* number type */
eltsz, /* element size */
nelms; /* number of elements */
int32 sds_id; /* data set identifier */
int32 sds_out = FAIL; /* data set identifier */
int32 dim_id; /* dimension identifier */
int32 sds_index; /* index number of the data set */
int32 dtype; /* SDS data type */
int32 dimsizes[H4_MAX_VAR_DIMS]; /* dimensions of SDS */
int32 start[H4_MAX_VAR_DIMS]; /* read start */
int32 edges[H4_MAX_VAR_DIMS]; /* read edges */
int32 nattrs; /* number of SDS attributes */
int32 rank; /* rank of SDS */
int32 numtype; /* number type */
int32 eltsz; /* element size */
int32 nelms; /* number of elements */
char sds_name[H4_MAX_NC_NAME];
void *buf = NULL;
int i, j, ret = 1;
Expand Down Expand Up @@ -618,7 +608,7 @@ gen_dim(char *name, /* name of SDS */
*/

/* alloc */
if ((buf = (void *)malloc(nelms * eltsz)) == NULL) {
if ((buf = (void *)malloc((size_t)(nelms * eltsz))) == NULL) {
printf("Failed to allocate %d elements of size %d\n", nelms, eltsz);
ret = -1;
goto out;
Expand Down Expand Up @@ -668,16 +658,10 @@ gen_dim(char *name, /* name of SDS */
* Function: match_dim_table_add
*
* Purpose: add an entry from a list of dimension names into the match table
*
* Programmer: Pedro Vicente, pvn@hdfgroup.org
*
* Date: January 17, 2007
*
*-------------------------------------------------------------------------
*/

static void
match_dim_table_add(match_dim_table_t *mdim_tbl, unsigned *flags, char *dim_name, int32 ref)
match_dim_table_add(match_dim_table_t *mdim_tbl, int *flags, char *dim_name, int32 ref)
{
int i;

Expand All @@ -696,7 +680,7 @@ match_dim_table_add(match_dim_table_t *mdim_tbl, unsigned *flags, char *dim_name
if (mdim_tbl->nobjs == mdim_tbl->size) {
mdim_tbl->size *= 2;
mdim_tbl->objs =
(match_dim_name_t *)realloc(mdim_tbl->objs, mdim_tbl->size * sizeof(match_dim_name_t));
(match_dim_name_t *)realloc(mdim_tbl->objs, (size_t)mdim_tbl->size * sizeof(match_dim_name_t));

for (i = mdim_tbl->nobjs; i < mdim_tbl->size; i++) {
mdim_tbl->objs[i].ref = -1;
Expand All @@ -717,14 +701,8 @@ match_dim_table_add(match_dim_table_t *mdim_tbl, unsigned *flags, char *dim_name
* Purpose: initialize match table
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@hdfgroup.org
*
* Date: January 17, 2007
*
*-------------------------------------------------------------------------
*/

static void
match_dim_table_init(match_dim_table_t **tbl)
{
Expand All @@ -733,7 +711,7 @@ match_dim_table_init(match_dim_table_t **tbl)

mdim_tbl->size = 20;
mdim_tbl->nobjs = 0;
mdim_tbl->objs = (match_dim_name_t *)malloc(mdim_tbl->size * sizeof(match_dim_name_t));
mdim_tbl->objs = (match_dim_name_t *)malloc((size_t)mdim_tbl->size * sizeof(match_dim_name_t));

for (i = 0; i < mdim_tbl->size; i++) {
mdim_tbl->objs[i].ref = -1;
Expand All @@ -749,14 +727,8 @@ match_dim_table_init(match_dim_table_t **tbl)
* Purpose: free match table
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@hdfgroup.org
*
* Date: January 17, 2007
*
*-------------------------------------------------------------------------
*/

static void
match_dim_table_free(match_dim_table_t *mdim_tbl)
{
Expand All @@ -770,22 +742,16 @@ match_dim_table_free(match_dim_table_t *mdim_tbl)
* Purpose: add an entry of pair REF/NAME into a dimension table
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@hdfgroup.org
*
* Date: January 17, 2007
*
*-------------------------------------------------------------------------
*/

void
dim_table_add(dim_table_t *dim_tbl, int ref, char *name)
{
int i;

if (dim_tbl->nobjs == dim_tbl->size) {
dim_tbl->size *= 2;
dim_tbl->objs = (dim_name_t *)realloc(dim_tbl->objs, dim_tbl->size * sizeof(dim_name_t));
dim_tbl->objs = (dim_name_t *)realloc(dim_tbl->objs, (size_t)dim_tbl->size * sizeof(dim_name_t));

for (i = dim_tbl->nobjs; i < dim_tbl->size; i++) {
dim_tbl->objs[i].ref = -1;
Expand All @@ -803,14 +769,8 @@ dim_table_add(dim_table_t *dim_tbl, int ref, char *name)
* Purpose: initialize dimension table
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@hdfgroup.org
*
* Date: January 17, 2007
*
*-------------------------------------------------------------------------
*/

void
dim_table_init(dim_table_t **tbl)
{
Expand All @@ -819,7 +779,7 @@ dim_table_init(dim_table_t **tbl)

dim_tbl->size = 20;
dim_tbl->nobjs = 0;
dim_tbl->objs = (dim_name_t *)malloc(dim_tbl->size * sizeof(dim_name_t));
dim_tbl->objs = (dim_name_t *)malloc((size_t)dim_tbl->size * sizeof(dim_name_t));

for (i = 0; i < dim_tbl->size; i++) {
dim_tbl->objs[i].ref = -1;
Expand All @@ -834,14 +794,8 @@ dim_table_init(dim_table_t **tbl)
* Purpose: free dimension table
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@hdfgroup.org
*
* Date: January 17, 2007
*
*-------------------------------------------------------------------------
*/

void
dim_table_free(dim_table_t *dim_tbl)
{
Expand Down
Loading

0 comments on commit 882e76a

Please sign in to comment.