diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/h5import/h5import.c | 25 | ||||
-rwxr-xr-x | tools/h5import/h5import.h | 3 | ||||
-rw-r--r-- | tools/h5jam/h5jamgentest.c | 2 | ||||
-rw-r--r-- | tools/h5repack/h5repack.c | 22 | ||||
-rw-r--r-- | tools/h5repack/h5repack_opttable.c | 18 | ||||
-rw-r--r-- | tools/h5repack/h5repacktst.c | 16 |
6 files changed, 51 insertions, 35 deletions
diff --git a/tools/h5import/h5import.c b/tools/h5import/h5import.c index 3818829..60ef494 100755 --- a/tools/h5import/h5import.c +++ b/tools/h5import/h5import.c @@ -1587,16 +1587,29 @@ static int parsePathInfo(struct path_info *path, char *temp) { const char delimiter[] = "/"; - char *token = (char*) malloc(255*sizeof(char)); + char *token; int i=0; + const char *err1 = "Path string larger than MAX_PATH_NAME_LENGTH.\n"; + + token = HDstrtok (temp, delimiter); + if (HDstrlen(token) >= MAX_PATH_NAME_LENGTH) + { + (void) fprintf(stderr, err1); + return (-1); + } + HDstrcpy(path->group[i++],token); - HDstrcpy(path->group[i++],HDstrtok (temp, delimiter)); while (1) { token = HDstrtok (NULL, delimiter); if (token == NULL) break; + if (HDstrlen(token) >= MAX_PATH_NAME_LENGTH) + { + (void) fprintf(stderr, err1); + return (-1); + } HDstrcpy(path->group[i++],token); } path->count = i; @@ -1608,11 +1621,12 @@ parseDimensions(struct Input *in, char *strm) { const char delimiter[] = ","; char temp[255]; - char *token = (char*) malloc(255*sizeof(char)); + char *token; int i=0; const char *err1 = "Unable to allocate dynamic memory.\n"; - HDstrcpy(temp, strm); + HDstrncpy(temp, strm, sizeof(temp)); + temp[sizeof(temp)-1] = '\0'; HDstrtok (temp, delimiter); while (1) @@ -1631,7 +1645,8 @@ parseDimensions(struct Input *in, char *strm) } i=0; - HDstrcpy(temp, strm); + HDstrncpy(temp, strm, sizeof(temp)); + temp[sizeof(temp)-1] = '\0'; in->sizeOfDimension[i++] = HDstrtol(HDstrtok (temp, delimiter), NULL, BASE_10); while (1) diff --git a/tools/h5import/h5import.h b/tools/h5import/h5import.h index c43b0cf..cbc6bf2 100755 --- a/tools/h5import/h5import.h +++ b/tools/h5import/h5import.h @@ -38,6 +38,7 @@ #define ERR 20 /* invalid token */ #define MAX_GROUPS_IN_PATH 20 +#define MAX_PATH_NAME_LENGTH 255 #define NUM_KEYS 14 #define MIN_NUM_DIMENSION 1 #define MAX_NUM_DIMENSION 32 @@ -73,7 +74,7 @@ struct path_info { - char group[MAX_GROUPS_IN_PATH][255]; + char group[MAX_GROUPS_IN_PATH][MAX_PATH_NAME_LENGTH]; int count; }; diff --git a/tools/h5jam/h5jamgentest.c b/tools/h5jam/h5jamgentest.c index 5a3d828..96d113e 100644 --- a/tools/h5jam/h5jamgentest.c +++ b/tools/h5jam/h5jamgentest.c @@ -345,6 +345,8 @@ create_textfile(const char *name, size_t size) HDwrite(fd, buf, size); + free(buf); + HDclose(fd); } diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index c67eb0a..473090f 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -112,6 +112,7 @@ h5repack_init(pack_opt_t *options, int verbose, H5F_file_space_type_t strategy, return (options_table_init(&(options->op_tbl))); } + /*------------------------------------------------------------------------- * Function: h5repack_end * @@ -125,6 +126,7 @@ int h5repack_end (pack_opt_t *options) return options_table_free(options->op_tbl); } + /*------------------------------------------------------------------------- * Function: h5repack_addfilter * @@ -135,7 +137,6 @@ int h5repack_end (pack_opt_t *options) * *------------------------------------------------------------------------- */ - int h5repack_addfilter(const char* str, pack_opt_t *options) { @@ -147,38 +148,33 @@ int h5repack_addfilter(const char* str, /* parse the -f option */ - obj_list=parse_filter(str,&n_objs,&filter,options,&is_glb); - if (obj_list==NULL) - { + if(NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb))) return -1; - } /* if it applies to all objects */ - if (is_glb) + if(is_glb) { - int n; n = options->n_filter_g++; /* increase # of global filters */ - if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) + if(options->n_filter_g > H5_REPACK_MAX_NFILTERS) { - error_msg(progname, "maximum number of filters exceeded for <%s>\n",str); + error_msg(progname, "maximum number of filters exceeded for <%s>\n", str); + free(obj_list); return -1; - } options->filter_g[n] = filter; } - else - options_add_filter(obj_list,n_objs,filter,options->op_tbl); + options_add_filter(obj_list, n_objs, filter, options->op_tbl); free(obj_list); return 0; } - + /*------------------------------------------------------------------------- * Function: h5repack_addlayout * diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index 5b6d5d0..7c87359 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -136,6 +136,7 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs ) return 0; } + /*------------------------------------------------------------------------- * Function: options_table_init * @@ -145,33 +146,34 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs ) * *------------------------------------------------------------------------- */ - int options_table_init( pack_opttbl_t **tbl ) { unsigned int i; - pack_opttbl_t* table = (pack_opttbl_t*) malloc(sizeof(pack_opttbl_t)); - if (table==NULL) { + pack_opttbl_t *table; + + if(NULL == (table = (pack_opttbl_t *)malloc(sizeof(pack_opttbl_t)))) + { error_msg(progname, "not enough memory for options table\n"); return -1; } table->size = 30; table->nelems = 0; - table->objs = (pack_info_t*) malloc(table->size * sizeof(pack_info_t)); - if (table->objs==NULL) { + if(NULL == (table->objs = (pack_info_t*)malloc(table->size * sizeof(pack_info_t)))) + { error_msg(progname, "not enough memory for options table\n"); + free(table); return -1; } - for ( i=0; i<table->size; i++) - { + for(i = 0; i < table->size; i++) init_packobject(&table->objs[i]); - } *tbl = table; return 0; } + /*------------------------------------------------------------------------- * Function: options_table_free * diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c index 3dcde22..3283ddd 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -4056,6 +4056,7 @@ int make_dset_reg_ref(hid_t loc_id) hdset_reg_ref_t *wbuf=NULL; /* buffer to write to disk */ int *dwbuf=NULL; /* Buffer for writing numeric data to disk */ int i; /* counting variables */ + int retval = -1; /* return value */ /* Allocate write & read buffers */ wbuf = (hdset_reg_ref_t *)calloc(sizeof(hdset_reg_ref_t), (size_t)SPACE1_DIM1); @@ -4111,24 +4112,23 @@ int make_dset_reg_ref(hid_t loc_id) if (H5Dclose(did2) < 0) goto out; - if (wbuf) + retval = 0; + +out: + if(wbuf) free(wbuf); - if (dwbuf) + if(dwbuf) free(dwbuf); - return 0; - -out: H5E_BEGIN_TRY { - H5Sclose(sid1); H5Sclose(sid2); H5Dclose(did1); H5Dclose(did2); - } H5E_END_TRY; - return -1; + + return retval; } /*------------------------------------------------------------------------- |