Skip to content

Commit

Permalink
Fix misc gcc warnings (#570)
Browse files Browse the repository at this point in the history
* Remove dead code in hdf/src/mfan.c
* Add const to many constant string initializations
* Fix some integer type mismatch with casts
* Fix logic and parentheses in szip test
* Clarify ambiguous brackets
* Turn off format-nonliteral warnings
  • Loading branch information
derobins authored Feb 20, 2024
1 parent 91ac289 commit ed45b86
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 180 deletions.
1 change: 1 addition & 0 deletions config/gnu-warnings/no-developer-general
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
# regarding the library settings string (H4libhdf4_settings). We'll turn
# it off here but leave it on in the developer flags.
-Wno-overlength-strings
-Wno-format-nonliteral
67 changes: 0 additions & 67 deletions hdf/src/mfan.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,73 +569,6 @@ ANIcreate_ann_tree(int32 an_id,/* IN: annotation interface id */
return ret_value;
} /* ANIcreate_ann_tree */

#if NOT_USED_YET
/*--------------------------------------------------------------------------
NAME
ANIfind -- find annotation id for given annotation type and ref number
DESCRIPTION
Find annotation id for the given annotation type and ref number
RETURNS
Annotation id if successful and FAIL (-1) otherwise
AUTHOR
GeorgeV.
-------------------------------------------------------------------------*/
static int32
ANIfind(int32 an_id, /* IN: annotation interface id */
ann_type type, /* IN: AN_DATA_LABEL for data labels,
AN_DATA_DESC for data descriptions,
AN_FILE_LABEL for file labels,
AN_FILE_DESC for file descriptions.*/
uint16 ann_ref /* IN: ref of annotation */)
{
filerec_t *file_rec = NULL; /* file record pointer */
TBBT_NODE *entry = NULL;
ANentry *ann_entry = NULL;
int32 ann_key;
int32 ret_value = SUCCEED;

/* Clear error stack */
HEclear();

/* convert an_id i.e. file_id to file rec and check for validity */
file_rec = HAatom_object(an_id);
if (BADFREC(file_rec))
HGOTO_ERROR(DFE_ARGS, FAIL);

/* Check for empty annotation tree of 'type'? */
if (file_rec->an_num[type] == -1) {
if ((file_rec->an_tree[type] = (TBBT_TREE *)tbbtdmake(ANIanncmp, sizeof(int32), 0)) == NULL) {
HE_REPORT_GOTO("failed to create annotation tree", FAIL);
}

file_rec->an_num[type] = 0; /* initialize after allocation */
}

/* Create key from type/ref pair
* ----------------------------
* | type(16bits) | ref(16bits) |
* -----------------------------*/
ann_key = AN_CREATE_KEY(type, ann_ref);

/* See if annotation of 'type' with ref exits */
if ((entry = tbbtdfind(file_rec->an_tree[type], &ann_key, NULL)) == NULL)
HE_REPORT_GOTO("failed to find annotation of 'type'", FAIL);

/* get annotation entry from node */
ann_entry = (ANentry *)entry->data;

/* return annotation id */
ret_value = ann_entry->ann_id;

done:
return ret_value;
} /* ANIfind */
#endif /* NOT_USED_YET */

/*--------------------------------------------------------------------------
NAME
ANInumann -- find number of annotation of 'type' that
Expand Down
13 changes: 7 additions & 6 deletions hdf/test/mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4431,12 +4431,13 @@ test_mgr_chunkwr_pixel(int flag)
data_type, /* data type of the image data */
comp_flag, /* compression flag */
index, i;
int32 start[2], stride[2], edge[2];
intn is_mappedable; /* TRUE if the image is mapped-able (hmap project)*/
intn name_generated; /* TRUE if the image has name generated by lib */
int16 data_out[3 * Y_LENGTH * X_LENGTH];
char *image_name[] = {"Image_NO", "Image_RL", "Image_Sk", "Image_DF"};
char *file_name[] = {"ChunkedGR_NO.hdf", "ChunkedGR_RL.hdf", "ChunkedGR_SK.hdf", "ChunkedGR_DF.hdf"};
int32 start[2], stride[2], edge[2];
intn is_mappedable; /* TRUE if the image is mapped-able (hmap project)*/
intn name_generated; /* TRUE if the image has name generated by lib */
int16 data_out[3 * Y_LENGTH * X_LENGTH];
const char *image_name[] = {"Image_NO", "Image_RL", "Image_Sk", "Image_DF"};
const char *file_name[] = {"ChunkedGR_NO.hdf", "ChunkedGR_RL.hdf", "ChunkedGR_SK.hdf",
"ChunkedGR_DF.hdf"};
HDF_CHUNK_DEF chunk_def;
int16 chunk_buf[18];

Expand Down
24 changes: 12 additions & 12 deletions hdf/test/tattdatainfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,18 +406,18 @@ test_vgmixedattrs()

/* Test Vattrinfo2 and Vgetattr2 on each attribute */
for (ii = 0; ii < n_attrs; ii++) {
char aname[20];
int32 atype, acount, asize, n_fields;
uint16 refnum;
int jj;
char cvalues[20];
int32 ivalues[10];
char *check_attr_names[5] = {"Attribute 6", "Attribute 7", "Attribute 1", "Attribute 2",
"Attribute 5"};
char *check_attr_values[5] = {"VG0 oldattr0", "VG0 oldattr1",
"", /* int values, added by test_vvsattrs with attr1 */
"Vgroup0", /* added by test_vvsattrs with attr2 */
"VG0 newattr"};
char aname[20];
int32 atype, acount, asize, n_fields;
uint16 refnum;
int jj;
char cvalues[20];
int32 ivalues[10];
const char *check_attr_names[5] = {"Attribute 6", "Attribute 7", "Attribute 1", "Attribute 2",
"Attribute 5"};
const char *check_attr_values[5] = {"VG0 oldattr0", "VG0 oldattr1",
"", /* int values, added by test_vvsattrs with attr1 */
"Vgroup0", /* added by test_vvsattrs with attr2 */
"VG0 newattr"};

/* Get attribute information and verify its name and number of fields,
which should be 1 */
Expand Down
70 changes: 33 additions & 37 deletions hdf/test/tmgrcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ test_mgr_compress_a()
int32 start[2]; /* start of image data to grab */
int32 stride[2]; /* stride of image data to grab */
int32 count[2]; /* Size of image data to operate on */
intn i, j; /* indices */

/* Initialize data we are going to write out */
for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++)
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
image0[i][j] = (uint8)(i + j);

/* Get the first image in this file */
Expand Down Expand Up @@ -103,7 +102,7 @@ test_mgr_compress_a()
if (memcmp(image, image0, 10 * 10) != 0) {
MESSAGE(3, printf("Error reading data for gzip compressed image\n"););
num_errs++;
} /* end if */
}

/* Close the empty image */
ret = GRendaccess(riid);
Expand Down Expand Up @@ -159,7 +158,7 @@ test_mgr_compress_a()
if (memcmp(image, image0, 10 * 10) != 0) {
MESSAGE(3, printf("Error reading 2nd data for gzip compressed image\n"););
num_errs++;
} /* end if */
}

/* Close the empty image */
ret = GRendaccess(riid);
Expand Down Expand Up @@ -210,11 +209,10 @@ test_mgr_compress_b()
int32 interlace_mode, n_comps, n_attrs, datatype; /* Image information */
char name[30]; /* Buffer for retrieving image name */
uint8 attr; /* Attribute data */
intn i, j; /* indices */

/* Initialize data we are going to write out */
for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++)
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
image0[i][j] = (uint8)(i + j);

/* Get the first image in this file */
Expand Down Expand Up @@ -286,7 +284,7 @@ test_mgr_compress_b()
if (memcmp(image, image0, 10 * 10) != 0) {
MESSAGE(3, printf("Error reading data for gzip compressed image\n"););
num_errs++;
} /* end if */
}

/* Close the image */
ret = GRendaccess(riid);
Expand All @@ -309,16 +307,15 @@ test_mgr_compress_b()
static int
test_mgr_compress_c()
{
intn status; /* status for functions returning an intn */
int32 file_id, /* HDF file identifier */
gr_id, /* GR interface identifier */
ri_id, /* raster image identifier */
start[2], /* start position to write for each dimension */
edges[2], /* number of elements to be written along each dimension */
dim_sizes[2], /* dimension sizes of the image array */
interlace_mode, /* interlace mode of the image */
data_type, /* data type of the image data */
i, j;
int status; /* status for functions returning an int */
int32 file_id; /* HDF file identifier */
int32 gr_id; /* GR interface identifier */
int32 ri_id; /* raster image identifier */
int32 start[2]; /* start position to write for each dimension */
int32 edges[2]; /* number of elements to be written along each dimension */
int32 dim_sizes[2]; /* dimension sizes of the image array */
int32 interlace_mode; /* interlace mode of the image */
int32 data_type; /* data type of the image data */
uint8 image_buf[128][128][3];
uint8 read_buf[128][128][3];
comp_info c_info;
Expand Down Expand Up @@ -351,11 +348,11 @@ test_mgr_compress_c()
CHECK(status, FAIL, "GRsetcompress");

/* Fill the image data buffer with values */
for (i = 0; i < 128; i++)
for (j = 0; j < 128; j++) {
image_buf[i][j][0] = (i + j) + 1;
image_buf[i][j][1] = (i + j) + 1;
image_buf[i][j][2] = (i + j) + 1;
for (uint8 i = 0; i < 128; i++)
for (uint8 j = 0; j < 128; j++) {
image_buf[i][j][0] = (uint8)(i + j + 1);
image_buf[i][j][1] = (uint8)(i + j + 1);
image_buf[i][j][2] = (uint8)(i + j + 1);
}

/* Write data in the buffer into the image array */
Expand Down Expand Up @@ -399,7 +396,7 @@ test_mgr_compress_c()
if (fuzzy_memcmp(image_buf, read_buf, 128 * 128 * 3, JPEG_FUZZ) != 0) {
MESSAGE(3, printf("tmgrcomp: Error reading data for 24-bit JPEG compressed image\n"););
num_errs++;
} /* end if */
}

/* Terminate access to raster image and to GR */
/* interface and, close the HDF file. */
Expand Down Expand Up @@ -443,21 +440,20 @@ test_mgr_compress_c()
#define DEFLATE_LEVEL 7 /* arbitrary */
#define SKPHUFF_SKIPSIZE 28 /* arbitrary */

static intn
make_comp_image(int32 grid, char *img_name, comp_coder_t comp_type, /* Compression method */
comp_info *cinfo, char *message) /* Compression parameters */
static int
make_comp_image(int32 grid, const char *img_name, comp_coder_t comp_type, /* Compression method */
comp_info *cinfo, char *message) /* Compression parameters */
{
int32 riid; /* RI ID of the working image */
int32 dims[2] = {10, 10}; /* dimensions for the empty image */
uint8 image_data[10][10]; /* space for the image data */
int32 start[2]; /* start of image data to grab */
int32 stride[2]; /* stride of image data to grab */
intn i, j; /* indices */
intn ret_value; /* generic return value */
int ret_value; /* generic return value */

/* Initialize data we are going to write out */
for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++)
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
image_data[i][j] = (uint8)(i + j + 10);

/* Create the image */
Expand Down Expand Up @@ -502,7 +498,7 @@ test_get_compress()
comp_coder_t comp_type; /* Compression method */
comp_info cinfo; /* Compression parameters - union */
char err_func[80]; /* name of the functions where failure occurs */
intn status; /* generic return value */
int status; /* generic return value */

/* D - Retrieve compression information of compressed images */
MESSAGE(8, printf("Verify the compression information of compressed images\n"););
Expand Down Expand Up @@ -689,7 +685,7 @@ test_mgr_chunk_compress()

/************************* Variable declaration **************************/

intn status; /* status for functions returning an intn */
int status; /* status for functions returning an int */
int32 file_id, /* HDF file identifier */
gr_id, /* GR interface identifier */
ri_id[N_IMAGES], /* raster image identifier */
Expand All @@ -704,7 +700,7 @@ test_mgr_chunk_compress()

comp_coder_t comp_type;
int16 data_out[3 * Y_LENGTH * X_LENGTH];
char *image_name[] = {"Image_NO", "Image_RL", "Image_Sk", "Image_DF"};
const char *image_name[] = {"Image_NO", "Image_RL", "Image_Sk", "Image_DF"};
HDF_CHUNK_DEF chunk_def[N_IMAGES];
int16 chunk_buf[18];

Expand Down Expand Up @@ -879,7 +875,7 @@ test_mgr_chunk_compress()
MESSAGE(3, printf("Error in reading chunk at line %d\n", __LINE__););
MESSAGE(3, printf("Image #%d\n", (int)img_num););
num_errs++;
} /* end if */
}

/* Read the whole image. */
start[0] = start[1] = 0;
Expand All @@ -892,7 +888,7 @@ test_mgr_chunk_compress()
MESSAGE(3, printf("%d: Error reading data for the whole image\n", __LINE__););
MESSAGE(3, printf("%d: Compression method\n", (int)img_num););
num_errs++;
} /* end if */
}

status = GRendaccess(ri_id[img_num]);
CHECK(status, FAIL, "GRendaccess");
Expand Down
14 changes: 7 additions & 7 deletions hdf/test/tszip.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ test_szip_RI8bit()
/********************** End of variable declaration **********************/

HCget_config_info(COMP_CODE_SZIP, &comp_config);
CHECK_VOID((comp_config & COMP_DECODER_ENABLED | COMP_ENCODER_ENABLED), 0,
CHECK_VOID(((comp_config & COMP_DECODER_ENABLED) && (comp_config & COMP_ENCODER_ENABLED)), 0,
"SZIP Compression not available");

/* Create and open the file for sziped data */
Expand Down Expand Up @@ -347,7 +347,7 @@ test_szip_RI16bit()
/********************** End of variable declaration **********************/

HCget_config_info(COMP_CODE_SZIP, &comp_config);
CHECK_VOID((comp_config & COMP_DECODER_ENABLED | COMP_ENCODER_ENABLED), 0,
CHECK_VOID(((comp_config & COMP_DECODER_ENABLED) && (comp_config & COMP_ENCODER_ENABLED)), 0,
"SZIP Compression not available");

/* Create and open the file for sziped data */
Expand Down Expand Up @@ -560,7 +560,7 @@ test_szip_RI32bit()
/********************** End of variable declaration **********************/

HCget_config_info(COMP_CODE_SZIP, &comp_config);
CHECK_VOID((comp_config & COMP_DECODER_ENABLED | COMP_ENCODER_ENABLED), 0,
CHECK_VOID(((comp_config & COMP_DECODER_ENABLED) && (comp_config & COMP_ENCODER_ENABLED)), 0,
"SZIP Compression not available");

/* Create and open the file for sziped data */
Expand Down Expand Up @@ -773,7 +773,7 @@ test_szip_RIfl32bit()
/********************** End of variable declaration **********************/

HCget_config_info(COMP_CODE_SZIP, &comp_config);
CHECK_VOID((comp_config & COMP_DECODER_ENABLED | COMP_ENCODER_ENABLED), 0,
CHECK_VOID(((comp_config & COMP_DECODER_ENABLED) && (comp_config & COMP_ENCODER_ENABLED)), 0,
"SZIP Compression not available");

/* Create and open the file for sziped data */
Expand Down Expand Up @@ -987,7 +987,7 @@ test_szip_RIfl64bit()
/********************** End of variable declaration **********************/

HCget_config_info(COMP_CODE_SZIP, &comp_config);
CHECK_VOID((comp_config & COMP_DECODER_ENABLED | COMP_ENCODER_ENABLED), 0,
CHECK_VOID(((comp_config & COMP_DECODER_ENABLED) && (comp_config & COMP_ENCODER_ENABLED)), 0,
"SZIP Compression not available");

/* Create and open the file for sziped data */
Expand Down Expand Up @@ -1144,7 +1144,7 @@ test_szip_chunk()
uint32 comp_config;
comp_coder_t comp_type;
int8 data_out[N_COMPS * LENGTH_CH * WIDTH_CH];
char *image_name = "Image_chunked_sziped";
const char *image_name = "Image_chunked_sziped";
HDF_CHUNK_DEF chunk_def;
int8 chunk_buf[18];

Expand All @@ -1169,7 +1169,7 @@ test_szip_chunk()
/********************** End of variable declaration **********************/

HCget_config_info(COMP_CODE_SZIP, &comp_config);
CHECK_VOID((comp_config & COMP_DECODER_ENABLED | COMP_ENCODER_ENABLED), 0,
CHECK_VOID(((comp_config & COMP_DECODER_ENABLED) && (comp_config & COMP_ENCODER_ENABLED)), 0,
"SZIP Compression not available");

/* Create and open the file for chunked and sziped data. */
Expand Down
8 changes: 4 additions & 4 deletions hdf/util/he_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,10 @@ put(char *template, int verbose)
int
HEputR8(HE_CMD *cmd)
{
int i;
int verbose = NO;
char *image = "img#.@.%";
char *pal = "pal#";
int i;
int verbose = NO;
const char *image = "img#.@.%";
const char *pal = "pal#";

for (i = 1; i < cmd->argc; i++)
if (cmd->argv[i][0] == '-')
Expand Down
Loading

0 comments on commit ed45b86

Please sign in to comment.