summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/h4toh5anno.c12
-rw-r--r--tools/h4toh5image.c2
-rw-r--r--tools/h4toh5main.c4
-rw-r--r--tools/h4toh5sds.c2
-rw-r--r--tools/h4toh5util.c4
-rw-r--r--tools/h4toh5vdata.c12
-rw-r--r--tools/h5debug.c2
-rw-r--r--tools/h5dump.c19
-rw-r--r--tools/h5dumptst.c4
-rw-r--r--tools/h5ls.c7
-rw-r--r--tools/h5toh4.c9
-rw-r--r--tools/h5toh4.h20
-rw-r--r--tools/h5tools.c113
13 files changed, 111 insertions, 99 deletions
diff --git a/tools/h4toh5anno.c b/tools/h4toh5anno.c
index 31ba145..cd09e26 100644
--- a/tools/h4toh5anno.c
+++ b/tools/h4toh5anno.c
@@ -104,7 +104,7 @@ int Annofil_h4_to_h5(int32 file_id,hid_t h5group){
return FAIL;
}
- ann_buf = malloc(ann_length + 1);
+ ann_buf = malloc((size_t)ann_length + 1);
if(ann_buf == NULL) {
printf("error in allocating memory. \n");
return FAIL;
@@ -199,7 +199,7 @@ int Annofil_h4_to_h5(int32 file_id,hid_t h5group){
return FAIL;
}
- ann_buf = malloc(ann_length+1);
+ ann_buf = malloc((size_t)ann_length+1);
if(ann_buf == NULL) {
printf("error in allocating memory. \n");
ANend(an_id);
@@ -317,8 +317,8 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
int num_lab_anno;
int num_des_anno;
int32 istat;
- int32* des_anno_list;
- int32* lab_anno_list;
+ int32* des_anno_list=NULL;
+ int32* lab_anno_list=NULL;
char* ann_buf;
char* ann_obj_name;
@@ -380,7 +380,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
return FAIL;
}
- ann_buf = malloc(ann_length+1);
+ ann_buf = malloc((size_t)ann_length+1);
if(ann_buf == NULL) {
printf("error in allocating annotation memory.\n");
ANendaccess(ann_id);
@@ -487,7 +487,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
return FAIL;
}
- ann_buf = malloc(ann_length+1);
+ ann_buf = malloc((size_t)ann_length+1);
if(ann_buf == NULL) {
printf("error in allocating annotation memory.\n");
diff --git a/tools/h4toh5image.c b/tools/h4toh5image.c
index f3d41dc..c5bc1df 100644
--- a/tools/h4toh5image.c
+++ b/tools/h4toh5image.c
@@ -522,7 +522,7 @@ int gr_palette(int32 file_id,int32 ri_id,hid_t h5dset,hid_t h5_palgroup) {
int check_pal;
int check_palname;
int pal_stat;
- char* h5pal_name;
+ char* h5pal_name=NULL;
/* get palette id */
diff --git a/tools/h4toh5main.c b/tools/h4toh5main.c
index c936b1b..9881ce0 100644
--- a/tools/h4toh5main.c
+++ b/tools/h4toh5main.c
@@ -560,7 +560,7 @@ int get_numof_hdf4obj(char*filename,int32 file_id) {
int set_helpgroups(hid_t h5root,hid_t* h5dimgptr,hid_t* h5palgptr){
- hid_t h5_dimg;/* hdf5 dimensional scale group identifier. */
+ hid_t h5_dimg=(-1);/* hdf5 dimensional scale group identifier. */
hid_t h5_palg;/* hdf5 palette group identifier. */
/*1. dimensional scale group.*/
@@ -581,7 +581,7 @@ int set_helpgroups(hid_t h5root,hid_t* h5dimgptr,hid_t* h5palgptr){
h5_palg = H5Gcreate(h5root,HDF4_PALG,0);
if(h5_palg <0) {
printf("error in creating hdf5 palette group. \n");
- H5Gclose(h5_dimg);
+ if(h5_dimg>0) H5Gclose(h5_dimg);
return FAIL;
}
diff --git a/tools/h4toh5sds.c b/tools/h4toh5sds.c
index eb90e4c..89e5ddf 100644
--- a/tools/h4toh5sds.c
+++ b/tools/h4toh5sds.c
@@ -973,7 +973,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
attr_refDims[0] = count_h5objref;
attr_refSpace = H5Screate_simple(1,attr_refDims,NULL);
attr_refType = H5Tcopy(H5T_STD_REF_OBJ);
- alldim_refdat = calloc(count_h5objref,sizeof(hobj_ref_t));
+ alldim_refdat = calloc((size_t)count_h5objref,sizeof(hobj_ref_t));
if(alldim_refdat == NULL) {
printf("error in allocating memory. \n");
diff --git a/tools/h4toh5util.c b/tools/h4toh5util.c
index 64e32cf..879e8a9 100644
--- a/tools/h4toh5util.c
+++ b/tools/h4toh5util.c
@@ -933,7 +933,7 @@ hid_t mkstr(int size, H5T_str_t pad) {
hid_t type;
if((type=H5Tcopy(H5T_C_S1))<0) return -1;
- if((H5Tset_size(type,size))<0) return -1;
+ if((H5Tset_size(type,(size_t)size))<0) return -1;
if((H5Tset_strpad(type,pad))<0) return -1;
return type;
@@ -955,7 +955,7 @@ hid_t mkstr(int size, H5T_str_t pad) {
*/
int h4_transnumattr(hid_t h5g,const char *refname,uint16 group_ref) {
- hid_t h5memtype;
+ hid_t h5memtype=(-1);
hid_t h5a_id;
hid_t h5a_sid;
herr_t ret;
diff --git a/tools/h4toh5vdata.c b/tools/h4toh5vdata.c
index ed692a9..55a8bf9 100644
--- a/tools/h4toh5vdata.c
+++ b/tools/h4toh5vdata.c
@@ -28,6 +28,7 @@ Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
*****************************************************************************/
#include "h4toh5main.h"
+#include <assert.h>
/*-------------------------------------------------------------------------
* Function: Vdata_h4_to_h5
@@ -152,10 +153,11 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
return FAIL;
}
- h5memtype = calloc(nfields,sizeof(hid_t));
- h5type = calloc(nfields,sizeof(hid_t));
- h4memsize = calloc(nfields,sizeof(size_t));
- h4size = calloc(nfields,sizeof(size_t));
+ assert(nfields>0);
+ h5memtype = calloc((size_t)nfields,sizeof(hid_t));
+ h5type = calloc((size_t)nfields,sizeof(hid_t));
+ h4memsize = calloc((size_t)nfields,sizeof(size_t));
+ h4size = calloc((size_t)nfields,sizeof(size_t));
for (i=0;i<nfields;i++) {
@@ -199,7 +201,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
}
- vd_data = malloc(vdatamem_size*n_records);
+ vd_data = malloc((size_t)(vdatamem_size*n_records));
istat = VSsetfields(vdata_id,field_name_list);
diff --git a/tools/h5debug.c b/tools/h5debug.c
index 7f4e91a..76eb472 100644
--- a/tools/h5debug.c
+++ b/tools/h5debug.c
@@ -71,7 +71,7 @@ main(int argc, char *argv[])
*/
if (strchr (argv[1], '%')) {
plist = H5Pcreate (H5P_FILE_ACCESS);
- H5Pset_fapl_family (plist, 0, H5P_DEFAULT);
+ H5Pset_fapl_family (plist, (hsize_t)0, H5P_DEFAULT);
}
if ((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, plist)) < 0) {
fprintf(stderr, "cannot open file\n");
diff --git a/tools/h5dump.c b/tools/h5dump.c
index b8440a9..ae711a8 100644
--- a/tools/h5dump.c
+++ b/tools/h5dump.c
@@ -761,7 +761,7 @@ dump_selected_attr(hid_t loc_id, char *name)
H5G_stat_t statbuf;
j = (int)strlen(name) - 1;
- obj_name = malloc(j + 2);
+ obj_name = malloc((size_t)j + 2);
/* find the last / */
while (name[j] != '/' && j >=0)
@@ -771,7 +771,7 @@ dump_selected_attr(hid_t loc_id, char *name)
if (j == -1) {
strcpy(obj_name, "/");
} else {
- strncpy(obj_name, name, j+1);
+ strncpy(obj_name, name, (size_t)j+1);
obj_name[j+1] = '\0';
}
@@ -1245,7 +1245,7 @@ dump_data(hid_t obj_id, int obj_data)
void *buf;
hid_t space, type, p_type;
int ndims, i;
- hsize_t size[64], nelmts = 1;
+ hsize_t size[64], nelmts = 1, alloc_size;
int depth;
int stdindent = COL; /* should be 3*/
@@ -1276,7 +1276,9 @@ dump_data(hid_t obj_id, int obj_data)
for (i = 0; i < ndims; i++)
nelmts *= size[i];
- buf = malloc(nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type)));
+ alloc_size= nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type));
+ assert(alloc_size==(hsize_t)((size_t)alloc_size)); /*check for overflow*/
+ buf = malloc((size_t)alloc_size);
assert(buf);
if (H5Aread(obj_id, p_type, buf) >= 0)
@@ -1754,7 +1756,7 @@ main(int argc, const char *argv[])
/* init the find_objs_t */
info.threshold = 0;
info.prefix_len = prefix_len;
- info.prefix = malloc(info.prefix_len);
+ info.prefix = malloc((size_t)info.prefix_len);
info.prefix[0] = '\0';
info.group_table = group_table;
info.type_table = type_table;
@@ -1876,8 +1878,9 @@ print_enum(hid_t type)
}
/* Get the names and raw values of all members */
- name = calloc(nmembs, sizeof(char *));
- value = calloc(nmembs, MAX(H5Tget_size(type), dst_size));
+ assert(nmembs>0);
+ name = calloc((size_t)nmembs, sizeof(char *));
+ value = calloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size));
for (i = 0; i < nmembs; i++) {
name[i] = H5Tget_member_name(type, i);
@@ -1886,7 +1889,7 @@ print_enum(hid_t type)
/* Convert values to native data type */
if (native > 0)
- H5Tconvert(super, native, nmembs, value, NULL, H5P_DEFAULT);
+ H5Tconvert(super, native, (hsize_t)nmembs, value, NULL, H5P_DEFAULT);
/* Sort members by increasing value */
/*not implemented yet*/
diff --git a/tools/h5dumptst.c b/tools/h5dumptst.c
index f31658e..d10b0d3 100644
--- a/tools/h5dumptst.c
+++ b/tools/h5dumptst.c
@@ -1090,7 +1090,7 @@ static hid_t mkstr(int size, H5T_str_t pad) {
hid_t type;
if ((type=H5Tcopy(H5T_C_S1))<0) return -1;
- if (H5Tset_size(type, size)<0) return -1;
+ if (H5Tset_size(type, (size_t)size)<0) return -1;
if (H5Tset_strpad(type, pad)<0) return -1;
return type;
@@ -1452,7 +1452,7 @@ static void test_objref(void)
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
/* Create a group */
- group=H5Gcreate(fid1,"Group1",-1);
+ group=H5Gcreate(fid1,"Group1",(size_t)-1);
/* Set group's comment */
H5Gset_comment(group,".",write_comment);
diff --git a/tools/h5ls.c b/tools/h5ls.c
index 671ca42..4fdc673 100644
--- a/tools/h5ls.c
+++ b/tools/h5ls.c
@@ -833,15 +833,16 @@ display_enum_type(hid_t type, int ind)
}
/* Get the names and raw values of all members */
- name = calloc(nmembs, sizeof(char*));
- value = calloc(nmembs, MAX(H5Tget_size(type), dst_size));
+ assert(nmembs>0);
+ name = calloc((size_t)nmembs, sizeof(char*));
+ value = calloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size));
for (i=0; i<nmembs; i++) {
name[i] = H5Tget_member_name(type, i);
H5Tget_member_value(type, i, value+i*H5Tget_size(type));
}
/* Convert values to native data type */
- if (native>0) H5Tconvert(super, native, nmembs, value, NULL, H5P_DEFAULT);
+ if (native>0) H5Tconvert(super, native, (hsize_t)nmembs, value, NULL, H5P_DEFAULT);
/* Sort members by increasing value */
/*not implemented yet*/
diff --git a/tools/h5toh4.c b/tools/h5toh4.c
index 19f4bf3..30b381c 100644
--- a/tools/h5toh4.c
+++ b/tools/h5toh4.c
@@ -18,7 +18,7 @@
#include <h5tools.h>
-#if WIN32
+#ifdef WIN32
typedef unsigned int mode_t;
#endif
@@ -41,11 +41,8 @@ extern herr_t convert_dataset_string(hid_t, char *, op_data_t *);
extern int32 h5type_to_h4type(hid_t);
extern hid_t h4type_to_memtype(int32);
-extern void init_table(table_t **temp);
extern void free_table(table_t **temp);
-extern void init_prefix(char **prefix, int length);
extern void dump_tables(char* name, table_t* table);
-extern herr_t find_objs(hid_t , const char *, void *);
extern int get_table_idx(table_t*, unsigned long *);
extern int get_tableflag(table_t*, int);
extern int set_tableflag(table_t*, int);
@@ -129,7 +126,7 @@ main(int argc, char *argv[])
break;
}
#ifndef WIN32
- if (test_file(h5_filename,O_EXCL,292) != 0 ) { /* 292 Decimal - 0444 Octal, a+r */
+ if (test_file(h5_filename,O_EXCL,(mode_t)(S_IRUSR|S_IRGRP|S_IROTH)) != 0 ) { /* 292 Decimal - 0444 Octal, a+r */
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
status = -1;
break;
@@ -150,7 +147,7 @@ main(int argc, char *argv[])
break;
}
#ifndef WIN32
- if (test_file(h4_filename,O_CREAT|O_EXCL,436) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
+ if (test_file(h4_filename,O_CREAT|O_EXCL,(mode_t)(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
status = -1;
break;
diff --git a/tools/h5toh4.h b/tools/h5toh4.h
index a6ff37c..d268060 100644
--- a/tools/h5toh4.h
+++ b/tools/h5toh4.h
@@ -1,13 +1,3 @@
-#ifndef _H5TOH4_H
-#define _H5TOH4_H
-
-#include <mfhdf.h>
-#include <hdf5.h>
-
-#ifdef H5_HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
/*
* Copyright © 1998 NCSA
* All rights reserved.
@@ -18,6 +8,16 @@
* Purpose: Convert H5 files to H4 files.
*/
+#ifndef _H5TOH4_H
+#define _H5TOH4_H
+
+#include "hdf.h"
+#include "mfhdf.h"
+#include "hdf5.h"
+
+#ifdef H5_HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
typedef struct op_data_t {
/*
diff --git a/tools/h5tools.c b/tools/h5tools.c
index 1af7a6b..f88602d 100644
--- a/tools/h5tools.c
+++ b/tools/h5tools.c
@@ -52,11 +52,10 @@
#define H5DUMP_BUFSIZE (1024)
#endif
-#define OPT(X,S) ((X) ? (X) : (S))
-#define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z))
-
-#define START_OF_DATA 0x0001
-#define END_OF_DATA 0x0002
+#define OPT(X,S) ((X) ? (X) : (S))
+#define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z))
+#define START_OF_DATA 0x0001
+#define END_OF_DATA 0x0002
/* Special strings embedded in the output */
#define OPTIONAL_LINE_BREAK "\001"
@@ -105,13 +104,8 @@ typedef struct h5dump_context_t {
typedef herr_t (*H5G_operator_t)(hid_t, const char*, void*);
-extern int print_data(hid_t oid, hid_t _p_type, int obj_data);
-extern void init_prefix(char **temp, int length);
-extern void init_table(table_t **table);
extern void free_table(table_t **table);
extern void dump_table(char *name, table_t* table);
-extern herr_t find_objs(hid_t group, const char *name, void *op_data);
-extern int search_obj (table_t *temp, unsigned long *);
extern int get_table_idx(table_t *table, unsigned long *);
extern int get_tableflag(table_t*, int);
extern int set_tableflag(table_t*, int);
@@ -720,6 +714,7 @@ static int
h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/, const h5dump_t *info)
{
hssize_t nblocks, npoints;
+ hsize_t alloc_size;
hsize_t *ptdata;
int ndims = H5Sget_simple_extent_ndims(region);
@@ -729,62 +724,68 @@ h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/, const h5dump_t *info)
* the other.
*/
H5E_BEGIN_TRY {
- nblocks = H5Sget_select_hyper_nblocks(region);
- npoints = H5Sget_select_elem_npoints(region);
+ nblocks = H5Sget_select_hyper_nblocks(region);
+ npoints = H5Sget_select_elem_npoints(region);
} H5E_END_TRY;
h5dump_str_append(str, "{");
/* Print block information */
if (nblocks > 0) {
- int i;
+ int i;
- ptdata = malloc(nblocks * ndims * 2 * sizeof(ptdata[0]));
- H5Sget_select_hyper_blocklist(region, 0, nblocks, ptdata);
+ alloc_size=nblocks * ndims * 2 * sizeof(ptdata[0]);
+ assert(alloc_size==(hsize_t)((size_t)alloc_size)); /*check for overflow*/
+ ptdata = malloc((size_t)alloc_size);
+ H5_CHECK_OVERFLOW(nblocks,hssize_t,hsize_t);
+ H5Sget_select_hyper_blocklist(region, (hsize_t)0, (hsize_t)nblocks, ptdata);
- for (i = 0; i < nblocks; i++) {
- int j;
+ for (i = 0; i < nblocks; i++) {
+ int j;
- h5dump_str_append(str, info->dset_blockformat_pre,
- i ? "," OPTIONAL_LINE_BREAK " " : "",
- (unsigned long)i);
-
- /* Start coordinates and opposite corner */
- for (j = 0; j < ndims; j++)
- h5dump_str_append(str, "%s%lu", j ? "," : "(",
- (unsigned long)ptdata[i * 2 * ndims + j]);
+ h5dump_str_append(str, info->dset_blockformat_pre,
+ i ? "," OPTIONAL_LINE_BREAK " " : "",
+ (unsigned long)i);
+
+ /* Start coordinates and opposite corner */
+ for (j = 0; j < ndims; j++)
+ h5dump_str_append(str, "%s%lu", j ? "," : "(",
+ (unsigned long)ptdata[i * 2 * ndims + j]);
- for (j = 0; j < ndims; j++)
- h5dump_str_append(str, "%s%lu", j ? "," : ")-(",
- (unsigned long)ptdata[i * 2 * ndims + j + ndims]);
+ for (j = 0; j < ndims; j++)
+ h5dump_str_append(str, "%s%lu", j ? "," : ")-(",
+ (unsigned long)ptdata[i * 2 * ndims + j + ndims]);
- h5dump_str_append(str, ")");
- }
- free(ptdata);
+ h5dump_str_append(str, ")");
+ }
+ free(ptdata);
}
/* Print point information */
if (npoints > 0) {
- int i;
+ int i;
- ptdata = malloc(npoints * ndims * sizeof(ptdata[0]));
- H5Sget_select_elem_pointlist(region, 0, npoints, ptdata);
+ alloc_size=npoints * ndims * sizeof(ptdata[0]);
+ assert(alloc_size==(hsize_t)((size_t)alloc_size)); /*check for overflow*/
+ ptdata = malloc((size_t)alloc_size);
+ H5_CHECK_OVERFLOW(npoints,hssize_t,hsize_t);
+ H5Sget_select_elem_pointlist(region, (hsize_t)0, (hsize_t)npoints, ptdata);
- for (i = 0; i < npoints; i++) {
- int j;
+ for (i = 0; i < npoints; i++) {
+ int j;
- h5dump_str_append(str, info->dset_ptformat_pre ,
- i ? "," OPTIONAL_LINE_BREAK " " : "",
- (unsigned long)i);
-
- for (j = 0; j < ndims; j++)
- h5dump_str_append(str, "%s%lu", j ? "," : "(",
- (unsigned long)(ptdata[i * ndims + j]));
+ h5dump_str_append(str, info->dset_ptformat_pre ,
+ i ? "," OPTIONAL_LINE_BREAK " " : "",
+ (unsigned long)i);
+
+ for (j = 0; j < ndims; j++)
+ h5dump_str_append(str, "%s%lu", j ? "," : "(",
+ (unsigned long)(ptdata[i * ndims + j]));
- h5dump_str_append(str, ")");
- }
+ h5dump_str_append(str, ")");
+ }
- free(ptdata);
+ free(ptdata);
}
h5dump_str_append(str, "}");
@@ -1459,7 +1460,7 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
if (info->line_ncols > 0)
ncols = info->line_ncols;
- h5dump_simple_prefix(stream, info, ctx, 0, 0);
+ h5dump_simple_prefix(stream, info, ctx, (hsize_t)0, 0);
for (i = 0; i < nelmts; i++, ctx->cur_elmt++, elmt_counter++) {
/* Render the element */
@@ -1688,7 +1689,8 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
else
sm_nbytes = p_type_nbytes;
- sm_buf = malloc(sm_nbytes);
+ assert(sm_nbytes==(hsize_t)((size_t)sm_nbytes)); /*check for overflow*/
+ sm_buf = malloc((size_t)sm_nbytes);
sm_nelmts = sm_nbytes / p_type_nbytes;
sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
@@ -1920,8 +1922,9 @@ h5dump_fixtype(hid_t f_type)
* and add the members.
*/
nmembs = H5Tget_nmembers(f_type);
- memb = calloc(nmembs, sizeof(hid_t));
- name = calloc(nmembs, sizeof(char *));
+ assert(nmembs>0);
+ memb = calloc((size_t)nmembs, sizeof(hid_t));
+ name = calloc((size_t)nmembs, sizeof(char *));
for (i = 0, size = 0; i < nmembs; i++) {
@@ -2268,7 +2271,10 @@ init_table(table_t** temp)
void
init_prefix(char **prefix, int prefix_len)
{
- char *temp = malloc(prefix_len);
+ char *temp;
+
+ assert(prefix_len>0);
+ temp = malloc((size_t)prefix_len);
*temp = '\0';
*prefix = temp;
@@ -2621,7 +2627,10 @@ h5dump_fopen(const char *fname, char *drivername, size_t drivername_size)
hid_t fapl;
} driver[16];
static int ndrivers = 0;
- hid_t fid=(-1), fapl = H5P_DEFAULT;
+ hid_t fid=(-1);
+#ifdef VERSION13
+ hid_t fapl = H5P_DEFAULT;
+#endif
int drivernum;
if (!ndrivers) {