summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c++/src/H5CommonFG.cpp49
-rw-r--r--src/H5.c10
-rw-r--r--src/H5FDcore.c8
-rw-r--r--src/H5FDmulti.c110
-rw-r--r--src/H5Gint.c4
-rw-r--r--src/H5Gname.c53
-rw-r--r--src/H5system.c526
-rw-r--r--test/accum.c22
-rw-r--r--test/stab.c9
-rw-r--r--test/vfd.c219
-rw-r--r--tools/h5jam/h5unjam.c165
-rw-r--r--tools/lib/h5tools.c52
12 files changed, 623 insertions, 604 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index dcc331f..b3889a0 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -130,9 +130,7 @@ Group CommonFG::openGroup( const char* name ) const
// If the opening of the group failed, throw an exception
if( group_id < 0 )
- {
throwException("openGroup", "H5Gopen2 failed");
- }
// No failure, create and return the Group object
Group group( group_id );
@@ -174,9 +172,7 @@ DataSet CommonFG::createDataSet( const char* name, const DataType& data_type, co
// If the creation of the dataset failed, throw an exception
if( dataset_id < 0 )
- {
throwException("createDataSet", "H5Dcreate2 failed");
- }
// No failure, create and return the DataSet object
DataSet dataset( dataset_id );
@@ -270,9 +266,8 @@ void CommonFG::link( H5L_type_t link_type, const char* curr_name, const char* ne
break;
} /* end switch */
- if( ret_value < 0 ) {
+ if( ret_value < 0 )
throwException("link", "creating link failed");
- }
}
//--------------------------------------------------------------------------
@@ -300,9 +295,7 @@ void CommonFG::unlink( const char* name ) const
{
herr_t ret_value = H5Ldelete( getLocId(), name, H5P_DEFAULT );
if( ret_value < 0 )
- {
throwException("unlink", "H5Ldelete failed");
- }
}
//--------------------------------------------------------------------------
@@ -336,9 +329,7 @@ void CommonFG::move( const char* src, const char* dst ) const
{
herr_t ret_value = H5Lmove( getLocId(), src, H5L_SAME_LOC, dst, H5P_DEFAULT, H5P_DEFAULT );
if( ret_value < 0 )
- {
throwException("move", "H5Lmove failed");
- }
}
//--------------------------------------------------------------------------
@@ -371,9 +362,7 @@ void CommonFG::getObjinfo( const char* name, hbool_t follow_link, H5G_stat_t& st
{
herr_t ret_value = H5Gget_objinfo( getLocId(), name, follow_link, &statbuf );
if( ret_value < 0 )
- {
throwException("getObjinfo", "H5Gget_objinfo failed");
- }
}
//--------------------------------------------------------------------------
@@ -400,9 +389,7 @@ void CommonFG::getObjinfo( const char* name, H5G_stat_t& statbuf ) const
{
herr_t ret_value = H5Gget_objinfo( getLocId(), name, 0, &statbuf );
if( ret_value < 0 )
- {
throwException("getObjinfo", "H5Gget_objinfo failed");
- }
}
//--------------------------------------------------------------------------
@@ -440,9 +427,8 @@ H5std_string CommonFG::getLinkval( const char* name, size_t size ) const
{
ret_value = H5Lget_info(getLocId(), name, &linkinfo, H5P_DEFAULT);
if( ret_value < 0 )
- {
throwException("getLinkval", "H5Lget_info to find buffer size failed");
- }
+
val_size = linkinfo.u.val_size;
}
@@ -453,9 +439,8 @@ H5std_string CommonFG::getLinkval( const char* name, size_t size ) const
ret_value = H5Lget_val(getLocId(), name, value_C, val_size, H5P_DEFAULT);
if( ret_value < 0 )
- {
throwException("getLinkval", "H5Lget_val failed");
- }
+
value = H5std_string(value_C);
delete []value_C;
}
@@ -498,9 +483,7 @@ void CommonFG::setComment( const char* name, const char* comment ) const
{
herr_t ret_value = H5Oset_comment_by_name( getLocId(), name, comment, H5P_DEFAULT );
if( ret_value < 0 )
- {
throwException("setComment", "H5Oset_comment_by_name failed");
- }
}
//--------------------------------------------------------------------------
@@ -530,9 +513,7 @@ void CommonFG::removeComment(const char* name) const
{
herr_t ret_value = H5Oset_comment_by_name(getLocId(), name, NULL, H5P_DEFAULT);
if( ret_value < 0 )
- {
throwException("removeComment", "H5Oset_comment_by_name failed");
- }
}
//--------------------------------------------------------------------------
@@ -588,9 +569,8 @@ H5std_string CommonFG::getComment( const char* name, size_t bufsize ) const
// if H5Oget_comment_by_name returns SUCCEED, return the string comment,
// otherwise, throw an exception
if( ret_value < 0 )
- {
throwException("getComment", "H5Oget_comment_by_name failed");
- }
+
H5std_string comment = H5std_string(comment_C);
delete []comment_C;
return (comment);
@@ -628,9 +608,7 @@ void CommonFG::mount( const char* name, H5File& child, PropList& plist ) const
// Raise exception if H5Fmount returns negative value
if( ret_value < 0 )
- {
throwException("mount", "H5Fmount failed");
- }
}
//--------------------------------------------------------------------------
@@ -659,9 +637,7 @@ void CommonFG::unmount( const char* name ) const
// Raise exception if H5Funmount returns negative value
if( ret_value < 0 )
- {
throwException("unmount", "H5Funmount failed");
- }
}
//--------------------------------------------------------------------------
@@ -1006,9 +982,7 @@ hsize_t CommonFG::getNumObjs() const
herr_t ret_value = H5Gget_info(getLocId(), &ginfo);
if(ret_value < 0)
- {
throwException("getNumObjs", "H5Gget_info failed");
- }
return (ginfo.nlinks);
}
@@ -1032,9 +1006,7 @@ H5std_string CommonFG::getObjnameByIdx(hsize_t idx) const
// call H5Lget_name_by_idx with name as NULL to get its length
ssize_t name_len = H5Lget_name_by_idx(getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, NULL, 0, H5P_DEFAULT);
if(name_len < 0)
- {
throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
- }
// now, allocate C buffer to get the name
char* name_C = new char[name_len+1];
@@ -1067,9 +1039,8 @@ ssize_t CommonFG::getObjnameByIdx(hsize_t idx, char* name, size_t size) const
{
ssize_t name_len = H5Lget_name_by_idx(getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, name, size, H5P_DEFAULT);
if(name_len < 0)
- {
throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
- }
+
return (name_len);
}
@@ -1085,9 +1056,8 @@ ssize_t CommonFG::getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size)
char* name_C = new char[size];
ssize_t name_len = getObjnameByIdx(idx, name_C, size);
if(name_len < 0)
- {
throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
- }
+
name = H5std_string(name_C);
delete []name_C;
return (name_len);
@@ -1107,9 +1077,8 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx) const
{
H5G_obj_t obj_type = H5Gget_objtype_by_idx(getLocId(), idx);
if (obj_type == H5G_UNKNOWN)
- {
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
- }
+
return (obj_type);
}
@@ -1135,9 +1104,7 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx, char* type_name) const
case H5G_TYPE: HDstrcpy(type_name, "datatype"); break;
case H5G_UNKNOWN:
default:
- {
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
- }
}
return (obj_type);
}
@@ -1163,9 +1130,7 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx, H5std_string& type_name) const
case H5G_TYPE: type_name = H5std_string("datatype"); break;
case H5G_UNKNOWN:
default:
- {
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
- }
}
return (obj_type);
}
diff --git a/src/H5.c b/src/H5.c
index 4176d96..14ec7ca 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -714,14 +714,14 @@ H5check_version(unsigned majnum, unsigned minnum, unsigned relnum)
if (!disable_version_check){
/*
- *verify if H5_VERS_INFO is consistent with the other version information.
- *Check only the first sizeof(lib_str) char. Assume the information
- *will fit within this size or enough significance.
+ * Verify if H5_VERS_INFO is consistent with the other version information.
+ * Check only the first sizeof(lib_str) char. Assume the information
+ * will fit within this size or enough significance.
*/
- sprintf(lib_str, "HDF5 library version: %d.%d.%d",
+ HDsnprintf(lib_str, sizeof(lib_str), "HDF5 library version: %d.%d.%d",
H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE);
if(*substr) {
- HDstrcat(lib_str, "-");
+ HDstrncat(lib_str, "-", 1);
HDstrncat(lib_str, substr, (sizeof(lib_str) - HDstrlen(lib_str)) - 1);
} /* end if */
if (HDstrcmp(lib_str, H5_lib_vers_info_g)){
diff --git a/src/H5FDcore.c b/src/H5FDcore.c
index 03cc15e..43c8945 100644
--- a/src/H5FDcore.c
+++ b/src/H5FDcore.c
@@ -570,6 +570,14 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
ret_value = (H5FD_t *)file;
done:
+ if(!ret_value && file) {
+ if(file->fd >= 0)
+ HDclose(file->fd);
+ H5MM_xfree(file->name);
+ H5MM_xfree(file->mem);
+ H5MM_xfree(file);
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_core_open() */
diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c
index 16934e3..c2701c4 100644
--- a/src/H5FDmulti.c
+++ b/src/H5FDmulti.c
@@ -77,6 +77,7 @@
#define H5FD_MULTI_DXPL_PROP_NAME "H5FD_MULTI_DXPL"
#define H5FD_MULTI_DXPL_PROP_SIZE sizeof(H5FD_multi_dxpl_t)
+#define H5FD_MULT_MAX_FILE_NAME_LEN 1024
/* The driver identification number, initialized at runtime */
static hid_t H5FD_MULTI_g = 0;
@@ -207,12 +208,14 @@ static char *
my_strdup(const char *s)
{
char *x;
+ size_t str_len;
if(!s)
return NULL;
- if(NULL == (x = (char *)malloc(strlen(s) + 1)))
+ str_len = strlen(s) + 1;
+ if(NULL == (x = (char *)malloc(str_len)))
return NULL;
- strcpy(x, s);
+ memcpy(x, s, str_len);
return x;
}
@@ -301,7 +304,7 @@ H5Pset_fapl_split(hid_t fapl, const char *meta_ext, hid_t meta_plist_id,
H5FD_mem_t memb_map[H5FD_MEM_NTYPES];
hid_t memb_fapl[H5FD_MEM_NTYPES];
const char *memb_name[H5FD_MEM_NTYPES];
- char meta_name[1024], raw_name[1024];
+ char meta_name[H5FD_MULT_MAX_FILE_NAME_LEN], raw_name[H5FD_MULT_MAX_FILE_NAME_LEN];
haddr_t memb_addr[H5FD_MEM_NTYPES];
/*NO TRACE*/
@@ -324,25 +327,39 @@ H5Pset_fapl_split(hid_t fapl, const char *meta_ext, hid_t meta_plist_id,
/* The names */
/* process meta filename */
- if (meta_ext){
- if (strstr(meta_ext, "%s"))
- strcpy(meta_name, meta_ext);
+ if(meta_ext) {
+ if(strstr(meta_ext, "%s")) {
+ /* Note: this doesn't accommodate for when the '%s' in the user's
+ * string is at a position >sizeof(meta_name) - QK & JK - 2013/01/17
+ */
+ strncpy(meta_name, meta_ext, sizeof(meta_name));
+ meta_name[sizeof(meta_name) - 1] = '\0';
+ }
else
- sprintf(meta_name, "%%s%s", meta_ext);
+ snprintf(meta_name, sizeof(meta_name), "%%s%s", meta_ext);
+ }
+ else {
+ strncpy(meta_name, "%s.meta", sizeof(meta_name));
+ meta_name[sizeof(meta_name) - 1] = '\0';
}
- else
- strcpy(meta_name, "%s.meta");
memb_name[H5FD_MEM_SUPER] = meta_name;
/* process raw filename */
- if (raw_ext){
- if (strstr(raw_ext, "%s"))
- strcpy(raw_name, raw_ext);
+ if(raw_ext) {
+ if(strstr(raw_ext, "%s")) {
+ /* Note: this doesn't accommodate for when the '%s' in the user's
+ * string is at a position >sizeof(raw_name) - QK & JK - 2013/01/17
+ */
+ strncpy(raw_name, raw_ext, sizeof(raw_name));
+ raw_name[sizeof(raw_name) - 1] = '\0';
+ }
else
- sprintf(raw_name, "%%s%s", raw_ext);
+ snprintf(raw_name, sizeof(raw_name), "%%s%s", raw_ext);
+ }
+ else {
+ strncpy(raw_name, "%s.raw", sizeof(raw_name));
+ raw_name[sizeof(raw_name) - 1] = '\0';
}
- else
- strcpy(raw_name, "%s.raw");
memb_name[H5FD_MEM_DRAW] = raw_name;
/* The sizes */
@@ -471,7 +488,7 @@ H5Pset_fapl_multi(hid_t fapl_id, const H5FD_mem_t *memb_map,
if (!memb_name) {
assert(strlen(letters)==H5FD_MEM_NTYPES);
for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) {
- sprintf(_memb_name[mt], "%%s-%c.h5", letters[mt]);
+ snprintf(_memb_name[mt], sizeof(_memb_name[mt]), "%%s-%c.h5", letters[mt]);
_memb_name_ptrs[mt] = _memb_name[mt];
}
memb_name = _memb_name_ptrs;
@@ -573,12 +590,11 @@ H5Pget_fapl_multi(hid_t fapl_id, H5FD_mem_t *memb_map/*out*/,
memb_fapl[mt] = fa->memb_fapl[mt]; /*default or bad ID*/
}
}
- if (memb_name) {
- for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) {
- if (fa->memb_name[mt]) {
- memb_name[mt] = (char *)malloc(strlen(fa->memb_name[mt])+1);
- strcpy(memb_name[mt], fa->memb_name[mt]);
- } else
+ if(memb_name) {
+ for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; mt = (H5FD_mem_t)(mt + 1)) {
+ if(fa->memb_name[mt])
+ memb_name[mt] = my_strdup(fa->memb_name[mt]);
+ else
memb_name[mt] = NULL;
}
}
@@ -969,17 +985,17 @@ H5FD_multi_sb_encode(H5FD_t *_file, char *name/*out*/,
p += sizeof(haddr_t);
nseen++;
} END_MEMBERS;
- if (H5Tconvert(H5T_NATIVE_HADDR, H5T_STD_U64LE, nseen*2, buf+8, NULL,
- H5P_DEFAULT)<0)
+ if (H5Tconvert(H5T_NATIVE_HADDR, H5T_STD_U64LE, nseen*2, buf+8, NULL, H5P_DEFAULT)<0)
H5Epush_ret(func, H5E_ERR_CLS, H5E_DATATYPE, H5E_CANTCONVERT, "can't convert superblock info", -1)
/* Encode all name templates */
p = buf + 8 + nseen*2*8;
UNIQUE_MEMBERS(file->fa.memb_map, mt) {
size_t n = strlen(file->fa.memb_name[mt]) + 1;
- strcpy((char *)p, file->fa.memb_name[mt]);
+ strncpy((char *)p, file->fa.memb_name[mt], n);
p += n;
- for (i=n; i%8; i++) *p++ = '\0';
+ for (i=n; i%8; i++)
+ *p++ = '\0';
} END_MEMBERS;
return 0;
@@ -1209,19 +1225,21 @@ H5FD_multi_fapl_copy(const void *_old_fa)
ALL_MEMBERS(mt) {
if (old_fa->memb_fapl[mt]>=0) {
new_fa->memb_fapl[mt] = H5Pcopy(old_fa->memb_fapl[mt]);
- if (new_fa->memb_fapl[mt]<0) nerrors++;
+ if(new_fa->memb_fapl[mt]<0)
+ nerrors++;
}
if (old_fa->memb_name[mt]) {
- new_fa->memb_name[mt] = (char *)malloc(strlen(old_fa->memb_name[mt])+1);
+ new_fa->memb_name[mt] = my_strdup(old_fa->memb_name[mt]);
assert(new_fa->memb_name[mt]);
- strcpy(new_fa->memb_name[mt], old_fa->memb_name[mt]);
}
} END_MEMBERS;
if (nerrors) {
ALL_MEMBERS(mt) {
- if (new_fa->memb_fapl[mt]>=0) (void)H5Pclose(new_fa->memb_fapl[mt]);
- if (new_fa->memb_name[mt]) free(new_fa->memb_name[mt]);
+ if (new_fa->memb_fapl[mt]>=0)
+ (void)H5Pclose(new_fa->memb_fapl[mt]);
+ if (new_fa->memb_name[mt])
+ free(new_fa->memb_name[mt]);
} END_MEMBERS;
free(new_fa);
H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "invalid freespace objects", NULL)
@@ -2191,7 +2209,7 @@ compute_next(H5FD_multi_t *file)
static int
open_members(H5FD_multi_t *file)
{
- char tmp[1024];
+ char tmp[H5FD_MULT_MAX_FILE_NAME_LEN];
int nerrors=0;
static const char *func="(H5FD_multi)open_members"; /* Function Name for error reporting */
@@ -2199,30 +2217,28 @@ open_members(H5FD_multi_t *file)
H5Eclear2(H5E_DEFAULT);
UNIQUE_MEMBERS(file->fa.memb_map, mt) {
- if (file->memb[mt]) continue; /*already open*/
+ if(file->memb[mt])
+ continue; /*already open*/
assert(file->fa.memb_name[mt]);
- sprintf(tmp, file->fa.memb_name[mt], file->name);
+ /* Note: This truncates the user's filename down to only sizeof(tmp)
+ * characters. -QK & JK, 2013/01/17
+ */
+ snprintf(tmp, sizeof(tmp), file->fa.memb_name[mt], file->name);
#ifdef H5FD_MULTI_DEBUG
- if (file->flags & H5F_ACC_DEBUG) {
- fprintf(stderr, "H5FD_MULTI: open member %d \"%s\"\n",
- (int)mt, tmp);
- }
+ if(file->flags & H5F_ACC_DEBUG)
+ fprintf(stderr, "H5FD_MULTI: open member %d \"%s\"\n", (int)mt, tmp);
#endif
H5E_BEGIN_TRY {
- file->memb[mt] = H5FDopen(tmp, file->flags, file->fa.memb_fapl[mt],
- HADDR_UNDEF);
+ file->memb[mt] = H5FDopen(tmp, file->flags, file->fa.memb_fapl[mt], HADDR_UNDEF);
} H5E_END_TRY;
- if (!file->memb[mt]) {
+ if(!file->memb[mt]) {
#ifdef H5FD_MULTI_DEBUG
- if (file->flags & H5F_ACC_DEBUG) {
- fprintf(stderr, "H5FD_MULTI: open failed for member %d\n",
- (int)mt);
- }
+ if(file->flags & H5F_ACC_DEBUG)
+ fprintf(stderr, "H5FD_MULTI: open failed for member %d\n", (int)mt);
#endif
- if (!file->fa.relax || (file->flags & H5F_ACC_RDWR)) {
+ if(!file->fa.relax || (file->flags & H5F_ACC_RDWR))
nerrors++;
- }
}
} END_MEMBERS;
if (nerrors)
diff --git a/src/H5Gint.c b/src/H5Gint.c
index ad2e57e..fe8b995 100644
--- a/src/H5Gint.c
+++ b/src/H5Gint.c
@@ -928,7 +928,7 @@ H5G_visit_cb(const H5O_link_t *lnk, void *_udata)
/* Build the link's relative path name */
HDassert(udata->path[old_path_len] == '\0');
- HDstrcpy(&(udata->path[old_path_len]), lnk->name);
+ HDstrncpy(&(udata->path[old_path_len]), lnk->name, link_name_len + 1);
udata->curr_path_len += link_name_len;
/* Construct the link info from the link message */
@@ -992,7 +992,7 @@ H5G_visit_cb(const H5O_link_t *lnk, void *_udata)
/* Add the path separator to the current path */
HDassert(udata->path[udata->curr_path_len] == '\0');
- HDstrcpy(&(udata->path[udata->curr_path_len]), "/");
+ HDstrncpy(&(udata->path[udata->curr_path_len]), "/", 2);
udata->curr_path_len++;
/* Attempt to get the link info for this group */
diff --git a/src/H5Gname.c b/src/H5Gname.c
index 576d866..6619c86 100644
--- a/src/H5Gname.c
+++ b/src/H5Gname.c
@@ -293,7 +293,9 @@ static H5RS_str_t *
H5G_build_fullpath(const char *prefix, const char *name)
{
char *full_path; /* Full user path built */
+ size_t orig_path_len; /* Original length of the path */
size_t path_len; /* Length of the path */
+ size_t name_len; /* Length of the name */
unsigned need_sep; /* Flag to indicate if separator is needed */
H5RS_str_t *ret_value; /* Return value */
@@ -304,7 +306,7 @@ H5G_build_fullpath(const char *prefix, const char *name)
HDassert(name);
/* Get the length of the prefix */
- path_len = HDstrlen(prefix);
+ orig_path_len = path_len = HDstrlen(prefix);
/* Determine if there is a trailing separator in the name */
if(prefix[path_len - 1] == '/')
@@ -313,20 +315,21 @@ H5G_build_fullpath(const char *prefix, const char *name)
need_sep = 1;
/* Add in the length needed for the '/' separator and the relative path */
- path_len += HDstrlen(name) + need_sep;
+ name_len = HDstrlen(name);
+ path_len += name_len + need_sep;
/* Allocate space for the path */
if(NULL == (full_path = (char *)H5FL_BLK_MALLOC(str_buf, path_len + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* Build full path */
- HDstrcpy(full_path, prefix);
+ HDstrncpy(full_path, prefix, orig_path_len + 1);
if(need_sep)
- HDstrcat(full_path, "/");
- HDstrcat(full_path, name);
+ HDstrncat(full_path, "/", 1);
+ HDstrncat(full_path, name, name_len);
/* Create reference counted string for path */
- if((ret_value = H5RS_own(full_path)) == NULL)
+ if(NULL == (ret_value = H5RS_own(full_path)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
done:
@@ -423,7 +426,7 @@ H5G_build_fullpath_refstr_refstr(const H5RS_str_t *prefix_r, const H5RS_str_t *n
herr_t
H5G__name_init(H5G_name_t *name, const char *path)
{
- FUNC_ENTER_PACKAGE
+ FUNC_ENTER_PACKAGE_NOERR
/* Check arguments */
HDassert(name);
@@ -717,6 +720,7 @@ H5G_name_move_path(H5RS_str_t **path_r_ptr, const char *full_suffix, const char
path_len = HDstrlen(path);
if(full_suffix_len < path_len) {
const char *dst_suffix; /* Destination suffix that changes */
+ size_t dst_suffix_len; /* Length of destination suffix */
const char *src_suffix; /* Source suffix that changes */
size_t path_prefix_len; /* Length of path prefix */
const char *path_prefix2; /* 2nd prefix for path */
@@ -747,25 +751,26 @@ H5G_name_move_path(H5RS_str_t **path_r_ptr, const char *full_suffix, const char
/* Determine destination suffix */
dst_suffix = dst_path + (common_prefix_len - 1);
+ dst_suffix_len = HDstrlen(dst_suffix);
/* Compute path prefix before src suffix*/
path_prefix2 = path;
path_prefix2_len = path_prefix_len - HDstrlen(src_suffix);
/* Allocate space for the new path */
- new_path_len = path_prefix2_len + HDstrlen(dst_suffix) + full_suffix_len;
+ new_path_len = path_prefix2_len + dst_suffix_len + full_suffix_len;
if(NULL == (new_path = (char *)H5FL_BLK_MALLOC(str_buf, new_path_len + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
/* Create the new path */
if(path_prefix2_len > 0) {
HDstrncpy(new_path, path_prefix2, path_prefix2_len);
- HDstrcpy(new_path + path_prefix2_len, dst_suffix);
+ HDstrncpy(new_path + path_prefix2_len, dst_suffix, dst_suffix_len + 1);
} /* end if */
else
- HDstrcpy(new_path, dst_suffix);
+ HDstrncpy(new_path, dst_suffix, dst_suffix_len + 1);
if(full_suffix_len > 0)
- HDstrcat(new_path, full_suffix);
+ HDstrncat(new_path, full_suffix, full_suffix_len);
/* Release previous path */
H5RS_decr(*path_r_ptr);
@@ -887,23 +892,25 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
if(obj_in_child) {
const char *full_path; /* Full path of current object */
const char *src_path; /* Full path of source object */
+ size_t src_path_len; /* Length of source full path */
char *new_full_path; /* New full path of object */
size_t new_full_len; /* Length of new full path */
/* Get pointers to paths of interest */
full_path = H5RS_get_str(obj_path->full_path_r);
src_path = H5RS_get_str(names->src_full_path_r);
+ src_path_len = HDstrlen(src_path);
/* Build new full path */
/* Allocate space for the new full path */
- new_full_len = HDstrlen(src_path) + HDstrlen(full_path);
+ new_full_len = src_path_len + HDstrlen(full_path);
if(NULL == (new_full_path = (char *)H5FL_BLK_MALLOC(str_buf, new_full_len + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
/* Create the new full path */
- HDstrcpy(new_full_path, src_path);
- HDstrcat(new_full_path, full_path);
+ HDstrncpy(new_full_path, src_path, src_path_len + 1);
+ HDstrncat(new_full_path, full_path, new_full_len);
/* Release previous full path */
H5RS_decr(obj_path->full_path_r);
@@ -931,6 +938,7 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
if(obj_in_child) {
const char *full_path; /* Full path of current object */
const char *full_suffix; /* Full path after source path */
+ size_t full_suffix_len; /* Length of full path after source path */
const char *src_path; /* Full path of source object */
char *new_full_path; /* New full path of object */
@@ -940,13 +948,14 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
/* Construct full path suffix */
full_suffix = full_path + HDstrlen(src_path);
+ full_suffix_len = HDstrlen(full_suffix);
/* Build new full path */
/* Create the new full path */
- if(NULL == (new_full_path = (char *)H5FL_BLK_MALLOC(str_buf, HDstrlen(full_suffix) + 1)))
+ if(NULL == (new_full_path = (char *)H5FL_BLK_MALLOC(str_buf, full_suffix_len + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
- HDstrcpy(new_full_path, full_suffix);
+ HDstrncpy(new_full_path, full_suffix, full_suffix_len + 1);
/* Release previous full path */
H5RS_decr(obj_path->full_path_r);
@@ -992,10 +1001,12 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
if(H5G_common_path(obj_path->full_path_r, names->src_full_path_r)) {
const char *full_path; /* Full path of current object */
const char *full_suffix; /* Suffix of full path, after src_path */
+ size_t full_suffix_len; /* Length of suffix of full path after src_path*/
char *new_full_path; /* New full path of object */
size_t new_full_len; /* Length of new full path */
const char *src_path; /* Full path of source object */
const char *dst_path; /* Full path of destination object */
+ size_t dst_path_len; /* Length of destination's full path */
/* Sanity check */
HDassert(names->dst_full_path_r);
@@ -1004,6 +1015,7 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
full_path = H5RS_get_str(obj_path->full_path_r);
src_path = H5RS_get_str(names->src_full_path_r);
dst_path = H5RS_get_str(names->dst_full_path_r);
+ dst_path_len = HDstrlen(dst_path);
/* Make certain that the source and destination names are full (not relative) paths */
HDassert(*src_path == '/');
@@ -1011,6 +1023,7 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
/* Get pointer to "full suffix" */
full_suffix = full_path + HDstrlen(src_path);
+ full_suffix_len = HDstrlen(full_suffix);
/* Update the user path, if one exists */
if(obj_path->user_path_r)
@@ -1020,13 +1033,13 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
/* Build new full path */
/* Allocate space for the new full path */
- new_full_len = HDstrlen(dst_path) + HDstrlen(full_suffix);
+ new_full_len = dst_path_len + full_suffix_len;
if(NULL == (new_full_path = (char *)H5FL_BLK_MALLOC(str_buf, new_full_len + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
/* Create the new full path */
- HDstrcpy(new_full_path, dst_path);
- HDstrcat(new_full_path, full_suffix);
+ HDstrncpy(new_full_path, dst_path, dst_path_len + 1);
+ HDstrncat(new_full_path, full_suffix, full_suffix_len);
/* Release previous full path */
H5RS_decr(obj_path->full_path_r);
@@ -1318,7 +1331,7 @@ H5G_get_name_by_addr(hid_t file, hid_t lapl_id, hid_t dxpl_id, const H5O_loc_t *
/* If there's a buffer provided, copy into it, up to the limit of its size */
if(name) {
/* Copy the initial path separator */
- HDstrcpy(name, "/");
+ HDstrncpy(name, "/", 2);
/* Append the rest of the path */
/* (less one character, for the initial path separator) */
diff --git a/src/H5system.c b/src/H5system.c
index c0baee1..83cecba 100644
--- a/src/H5system.c
+++ b/src/H5system.c
@@ -122,24 +122,24 @@ HDfprintf(FILE *stream, const char *fmt, ...)
va_start (ap, fmt);
while (*fmt) {
- fwidth = prec = 0;
- zerofill = 0;
- leftjust = 0;
- plussign = 0;
- prefix = 0;
- ldspace = 0;
- modifier[0] = '\0';
-
- if ('%'==fmt[0] && '%'==fmt[1]) {
- HDputc ('%', stream);
- fmt += 2;
- nout++;
- } else if ('%'==fmt[0]) {
- s = fmt + 1;
-
- /* Flags */
- while(HDstrchr ("-+ #", *s)) {
- switch(*s) {
+ fwidth = prec = 0;
+ zerofill = 0;
+ leftjust = 0;
+ plussign = 0;
+ prefix = 0;
+ ldspace = 0;
+ modifier[0] = '\0';
+
+ if ('%'==fmt[0] && '%'==fmt[1]) {
+ HDputc ('%', stream);
+ fmt += 2;
+ nout++;
+ } else if ('%'==fmt[0]) {
+ s = fmt + 1;
+
+ /* Flags */
+ while(HDstrchr ("-+ #", *s)) {
+ switch(*s) {
case '-':
leftjust = 1;
break;
@@ -155,244 +155,251 @@ HDfprintf(FILE *stream, const char *fmt, ...)
case '#':
prefix = 1;
break;
- } /* end switch */ /*lint !e744 Switch statement doesn't _need_ default */
- s++;
- } /* end while */
-
- /* Field width */
- if (HDisdigit (*s)) {
- zerofill = ('0'==*s);
- fwidth = (int)HDstrtol (s, &rest, 10);
- s = rest;
- } else if ('*'==*s) {
- fwidth = va_arg (ap, int);
- if (fwidth<0) {
- leftjust = 1;
- fwidth = -fwidth;
- }
- s++;
- }
+ } /* end switch */ /*lint !e744 Switch statement doesn't _need_ default */
+ s++;
+ } /* end while */
+
+ /* Field width */
+ if(HDisdigit(*s)) {
+ zerofill = ('0' == *s);
+ fwidth = (int)HDstrtol (s, &rest, 10);
+ s = rest;
+ } /* end if */
+ else if ('*'==*s) {
+ fwidth = va_arg (ap, int);
+ if(fwidth < 0) {
+ leftjust = 1;
+ fwidth = -fwidth;
+ }
+ s++;
+ }
+
+ /* Precision */
+ if('.'==*s) {
+ s++;
+ if(HDisdigit(*s)) {
+ prec = (int)HDstrtol(s, &rest, 10);
+ s = rest;
+ } else if('*'==*s) {
+ prec = va_arg(ap, int);
+ s++;
+ }
+ if(prec < 1)
+ prec = 1;
+ }
+
+ /* Extra type modifiers */
+ if(HDstrchr("ZHhlqLI", *s)) {
+ switch(*s) {
+ /*lint --e{506} Don't issue warnings about constant value booleans */
+ /*lint --e{774} Don't issue warnings boolean within 'if' always evaluates false/true */
+ case 'H':
+ if(sizeof(hsize_t) < sizeof(long))
+ modifier[0] = '\0';
+ else if(sizeof(hsize_t) == sizeof(long))
+ HDstrncpy(modifier, "l", 2);
+ else
+ HDstrncpy(modifier, H5_PRINTF_LL_WIDTH, HDstrlen(H5_PRINTF_LL_WIDTH) + 1);
+ break;
- /* Precision */
- if ('.'==*s) {
- s++;
- if (HDisdigit (*s)) {
- prec = (int)HDstrtol (s, &rest, 10);
- s = rest;
- } else if ('*'==*s) {
- prec = va_arg (ap, int);
- s++;
- }
- if (prec<1) prec = 1;
- }
+ case 'Z':
+ if(sizeof(size_t) < sizeof(long))
+ modifier[0] = '\0';
+ else if(sizeof(size_t) == sizeof(long))
+ HDstrncpy(modifier, "l", 2);
+ else
+ HDstrncpy(modifier, H5_PRINTF_LL_WIDTH, HDstrlen(H5_PRINTF_LL_WIDTH) + 1);
+ break;
- /* Extra type modifiers */
- if (HDstrchr ("ZHhlqLI", *s)) {
- switch (*s) {
- /*lint --e{506} Don't issue warnings about constant value booleans */
- /*lint --e{774} Don't issue warnings boolean within 'if' always evaluates false/true */
- case 'H':
- if (sizeof(hsize_t)<sizeof(long)) {
- modifier[0] = '\0';
- } else if (sizeof(hsize_t)==sizeof(long)) {
- HDstrcpy (modifier, "l");
- } else {
- HDstrcpy (modifier, H5_PRINTF_LL_WIDTH);
- }
- break;
- case 'Z':
- if (sizeof(size_t)<sizeof(long)) {
- modifier[0] = '\0';
- } else if (sizeof(size_t)==sizeof(long)) {
- HDstrcpy (modifier, "l");
- } else {
- HDstrcpy (modifier, H5_PRINTF_LL_WIDTH);
- }
- break;
- default:
- /* Handle 'I64' modifier for Microsoft's "__int64" type */
- if(*s=='I' && *(s+1)=='6' && *(s+2)=='4') {
- modifier[0] = *s;
- modifier[1] = *(s+1);
- modifier[2] = *(s+2);
- modifier[3] = '\0';
- s+=2; /* Increment over 'I6', the '4' is taken care of below */
- } /* end if */
- else {
- /* Handle 'll' for long long types */
- if(*s=='l' && *(s+1)=='l') {
+ default:
+ /* Handle 'I64' modifier for Microsoft's "__int64" type */
+ if(*s=='I' && *(s+1)=='6' && *(s+2)=='4') {
modifier[0] = *s;
- modifier[1] = *s;
- modifier[2] = '\0';
- s++; /* Increment over first 'l', second is taken care of below */
+ modifier[1] = *(s+1);
+ modifier[2] = *(s+2);
+ modifier[3] = '\0';
+ s += 2; /* Increment over 'I6', the '4' is taken care of below */
} /* end if */
else {
- modifier[0] = *s;
- modifier[1] = '\0';
+ /* Handle 'll' for long long types */
+ if(*s=='l' && *(s+1)=='l') {
+ modifier[0] = *s;
+ modifier[1] = *s;
+ modifier[2] = '\0';
+ s++; /* Increment over first 'l', second is taken care of below */
+ } /* end if */
+ else {
+ modifier[0] = *s;
+ modifier[1] = '\0';
+ } /* end else */
} /* end else */
- } /* end else */
- break;
- }
- s++;
- }
-
- /* Conversion */
- conv = *s++;
-
- /* Create the format template */
- sprintf (format_templ, "%%%s%s%s%s%s",
- leftjust?"-":"", plussign?"+":"",
- ldspace?" ":"", prefix?"#":"", zerofill?"0":"");
- if (fwidth>0)
- sprintf (format_templ+HDstrlen(format_templ), "%d", fwidth);
- if (prec>0)
- sprintf (format_templ+HDstrlen(format_templ), ".%d", prec);
- if (*modifier)
- sprintf (format_templ+HDstrlen(format_templ), "%s", modifier);
- sprintf (format_templ+HDstrlen(format_templ), "%c", conv);
-
-
- /* Conversion */
- switch (conv) {
- case 'd':
- case 'i':
- if (!HDstrcmp(modifier, "h")) {
- short x = (short)va_arg (ap, int);
- n = fprintf (stream, format_templ, x);
- } else if (!*modifier) {
- int x = va_arg (ap, int);
- n = fprintf (stream, format_templ, x);
- } else if (!HDstrcmp (modifier, "l")) {
- long x = va_arg (ap, long);
- n = fprintf (stream, format_templ, x);
- } else {
- int64_t x = va_arg(ap, int64_t);
- n = fprintf (stream, format_templ, x);
- }
- break;
-
- case 'o':
- case 'u':
- case 'x':
- case 'X':
- if (!HDstrcmp (modifier, "h")) {
- unsigned short x = (unsigned short)va_arg (ap, unsigned int);
- n = fprintf (stream, format_templ, x);
- } else if (!*modifier) {
- unsigned int x = va_arg (ap, unsigned int); /*lint !e732 Loss of sign not really occuring */
- n = fprintf (stream, format_templ, x);
- } else if (!HDstrcmp (modifier, "l")) {
- unsigned long x = va_arg (ap, unsigned long); /*lint !e732 Loss of sign not really occuring */
- n = fprintf (stream, format_templ, x);
- } else {
- uint64_t x = va_arg(ap, uint64_t); /*lint !e732 Loss of sign not really occuring */
- n = fprintf (stream, format_templ, x);
- }
- break;
-
- case 'f':
- case 'e':
- case 'E':
- case 'g':
- case 'G':
- if (!HDstrcmp (modifier, "h")) {
- float x = (float) va_arg (ap, double);
- n = fprintf (stream, format_templ, x);
- } else if (!*modifier || !HDstrcmp (modifier, "l")) {
- double x = va_arg (ap, double);
- n = fprintf (stream, format_templ, x);
- } else {
- /*
- * Some compilers complain when `long double' and
- * `double' are the same thing.
- */
+ break;
+ }
+ s++;
+ }
+
+ /* Conversion */
+ conv = *s++;
+
+ /* Create the format template */
+ sprintf(format_templ, "%%%s%s%s%s%s", (leftjust ? "-" : ""),
+ (plussign ? "+" : ""), (ldspace ? " " : ""),
+ (prefix ? "#" : ""), (zerofill ? "0" : ""));
+ if(fwidth > 0)
+ sprintf(format_templ+HDstrlen(format_templ), "%d", fwidth);
+ if(prec > 0)
+ sprintf(format_templ+HDstrlen(format_templ), ".%d", prec);
+ if(*modifier)
+ sprintf(format_templ+HDstrlen(format_templ), "%s", modifier);
+ sprintf (format_templ+HDstrlen(format_templ), "%c", conv);
+
+
+ /* Conversion */
+ switch (conv) {
+ case 'd':
+ case 'i':
+ if(!HDstrcmp(modifier, "h")) {
+ short x = (short)va_arg (ap, int);
+ n = fprintf (stream, format_templ, x);
+ } else if(!*modifier) {
+ int x = va_arg (ap, int);
+ n = fprintf (stream, format_templ, x);
+ } else if(!HDstrcmp (modifier, "l")) {
+ long x = va_arg (ap, long);
+ n = fprintf (stream, format_templ, x);
+ } else {
+ int64_t x = va_arg(ap, int64_t);
+ n = fprintf (stream, format_templ, x);
+ }
+ break;
+
+ case 'o':
+ case 'u':
+ case 'x':
+ case 'X':
+ if(!HDstrcmp(modifier, "h")) {
+ unsigned short x = (unsigned short)va_arg (ap, unsigned int);
+ n = fprintf(stream, format_templ, x);
+ } else if(!*modifier) {
+ unsigned int x = va_arg (ap, unsigned int); /*lint !e732 Loss of sign not really occuring */
+ n = fprintf(stream, format_templ, x);
+ } else if(!HDstrcmp(modifier, "l")) {
+ unsigned long x = va_arg (ap, unsigned long); /*lint !e732 Loss of sign not really occuring */
+ n = fprintf(stream, format_templ, x);
+ } else {
+ uint64_t x = va_arg(ap, uint64_t); /*lint !e732 Loss of sign not really occuring */
+ n = fprintf(stream, format_templ, x);
+ }
+ break;
+
+ case 'f':
+ case 'e':
+ case 'E':
+ case 'g':
+ case 'G':
+ if(!HDstrcmp(modifier, "h")) {
+ float x = (float)va_arg(ap, double);
+ n = fprintf(stream, format_templ, x);
+ } else if(!*modifier || !HDstrcmp(modifier, "l")) {
+ double x = va_arg(ap, double);
+ n = fprintf(stream, format_templ, x);
+ } else {
+ /*
+ * Some compilers complain when `long double' and
+ * `double' are the same thing.
+ */
#if H5_SIZEOF_LONG_DOUBLE != H5_SIZEOF_DOUBLE
- long double x = va_arg (ap, long double);
- n = fprintf (stream, format_templ, x);
+ long double x = va_arg(ap, long double);
+ n = fprintf(stream, format_templ, x);
#else
- double x = va_arg (ap, double);
- n = fprintf (stream, format_templ, x);
+ double x = va_arg(ap, double);
+ n = fprintf(stream, format_templ, x);
#endif
- }
- break;
-
- case 'a':
- {
- haddr_t x = va_arg (ap, haddr_t); /*lint !e732 Loss of sign not really occuring */
- if (H5F_addr_defined(x)) {
- sprintf(format_templ, "%%%s%s%s%s%s",
- leftjust?"-":"", plussign?"+":"",
- ldspace?" ":"", prefix?"#":"",
- zerofill?"0":"");
- if (fwidth>0)
- sprintf(format_templ+HDstrlen(format_templ), "%d", fwidth);
-
- /*lint --e{506} Don't issue warnings about constant value booleans */
- /*lint --e{774} Don't issue warnings boolean within 'if' always evaluates false/true */
- if (sizeof(x)==H5_SIZEOF_INT) {
- HDstrcat(format_templ, "u");
- } else if (sizeof(x)==H5_SIZEOF_LONG) {
- HDstrcat(format_templ, "lu");
- } else if (sizeof(x)==H5_SIZEOF_LONG_LONG) {
- HDstrcat(format_templ, H5_PRINTF_LL_WIDTH);
- HDstrcat(format_templ, "u");
- }
- n = fprintf(stream, format_templ, x);
+ }
+ break;
+
+ case 'a':
+ {
+ haddr_t x = va_arg (ap, haddr_t); /*lint !e732 Loss of sign not really occuring */
+
+ if(H5F_addr_defined(x)) {
+ sprintf(format_templ, "%%%s%s%s%s%s",
+ (leftjust ? "-" : ""), (plussign ? "+" : ""),
+ (ldspace ? " " : ""), (prefix ? "#" : ""),
+ (zerofill ? "0" : ""));
+ if(fwidth > 0)
+ sprintf(format_templ + HDstrlen(format_templ), "%d", fwidth);
+
+ /*lint --e{506} Don't issue warnings about constant value booleans */
+ /*lint --e{774} Don't issue warnings boolean within 'if' always evaluates false/true */
+ if(sizeof(x) == H5_SIZEOF_INT)
+ HDstrcat(format_templ, "u");
+ else if(sizeof(x) == H5_SIZEOF_LONG)
+ HDstrcat(format_templ, "lu");
+ else if(sizeof(x) == H5_SIZEOF_LONG_LONG) {
+ HDstrcat(format_templ, H5_PRINTF_LL_WIDTH);
+ HDstrcat(format_templ, "u");
+ }
+ n = fprintf(stream, format_templ, x);
+ } else {
+ HDstrcpy(format_templ, "%");
+ if(leftjust)
+ HDstrcat(format_templ, "-");
+ if(fwidth)
+ sprintf(format_templ+HDstrlen(format_templ), "%d", fwidth);
+ HDstrcat(format_templ, "s");
+ fprintf(stream, format_templ, "UNDEF");
+ }
+ }
+ break;
+
+ case 'c':
+ {
+ char x = (char)va_arg(ap, int);
+ n = fprintf(stream, format_templ, x);
+ }
+ break;
+
+ case 's':
+ case 'p':
+ {
+ char *x = va_arg(ap, char*); /*lint !e64 Type mismatch not really occuring */
+ n = fprintf(stream, format_templ, x);
+ }
+ break;
+
+ case 'n':
+ format_templ[HDstrlen(format_templ) - 1] = 'u';
+ n = fprintf(stream, format_templ, nout);
+ break;
+
+ case 't':
+ {
+ htri_t tri_var = va_arg(ap, htri_t);
+
+ if(tri_var > 0)
+ fprintf (stream, "TRUE");
+ else if(!tri_var)
+ fprintf(stream, "FALSE");
+ else
+ fprintf(stream, "FAIL(%d)", (int)tri_var);
+ }
+ break;
+
+ default:
+ HDfputs(format_templ, stream);
+ n = (int)HDstrlen(format_templ);
+ break;
+ }
+ nout += n;
+ fmt = s;
} else {
- HDstrcpy(format_templ, "%");
- if (leftjust)
- HDstrcat(format_templ, "-");
- if (fwidth)
- sprintf(format_templ+HDstrlen(format_templ), "%d", fwidth);
- HDstrcat(format_templ, "s");
- fprintf(stream, format_templ, "UNDEF");
+ HDputc(*fmt, stream);
+ fmt++;
+ nout++;
}
}
- break;
-
- case 'c':
- {
- char x = (char)va_arg (ap, int);
- n = fprintf (stream, format_templ, x);
- }
- break;
-
- case 's':
- case 'p':
- {
- char *x = va_arg (ap, char*); /*lint !e64 Type mismatch not really occuring */
- n = fprintf (stream, format_templ, x);
- }
- break;
-
- case 'n':
- format_templ[HDstrlen(format_templ)-1] = 'u';
- n = fprintf (stream, format_templ, nout);
- break;
-
- case 't':
- {
- htri_t tri_var = va_arg (ap, htri_t);
- if (tri_var > 0) fprintf (stream, "TRUE");
- else if (!tri_var) fprintf (stream, "FALSE");
- else fprintf (stream, "FAIL(%d)", (int)tri_var);
- }
- break;
-
- default:
- HDfputs (format_templ, stream);
- n = (int)HDstrlen (format_templ);
- break;
- }
- nout += n;
- fmt = s;
- } else {
- HDputc (*fmt, stream);
- fmt++;
- nout++;
- }
- }
- va_end (ap);
+ va_end(ap);
return nout;
} /* end HDfprintf() */
@@ -713,23 +720,23 @@ H5_build_extpath(const char *name, char **extpath/*out*/)
if(NULL == (new_name = (char *)H5MM_strdup(name)))
HGOTO_ERROR(H5E_INTERNAL, H5E_NOSPACE, FAIL, "memory allocation failed")
- /*
- * Windows: name[0-1] is "<drive-letter>:"
- * Get current working directory on the drive specified in NAME
- * Unix: does not apply
+ /*
+ * Windows: name[0-1] is "<drive-letter>:"
+ * Get current working directory on the drive specified in NAME
+ * Unix: does not apply
* OpenVMS: does not apply
- */
+ */
if(CHECK_ABS_DRIVE(name)) {
drive = name[0] - 'A' + 1;
retcwd = HDgetdcwd(drive, cwdpath, MAX_PATH_LEN);
HDstrcpy(new_name, &name[2]);
} /* end if */
- /*
- * Windows: name[0] is a '/' or '\'
- * Get current drive
- * Unix: does not apply
- * OpenVMS: does not apply
- */
+ /*
+ * Windows: name[0] is a '/' or '\'
+ * Get current drive
+ * Unix: does not apply
+ * OpenVMS: does not apply
+ */
else if(CHECK_ABS_PATH(name) && (0 != (drive = HDgetdrive()))) {
sprintf(cwdpath, "%c:%c", (drive+'A'-1), name[0]);
retcwd = cwdpath;
@@ -749,7 +756,7 @@ H5_build_extpath(const char *name, char **extpath/*out*/)
if(NULL == (full_path = (char *)H5MM_malloc(path_len)))
HGOTO_ERROR(H5E_INTERNAL, H5E_NOSPACE, FAIL, "memory allocation failed")
- HDstrcpy(full_path, cwdpath);
+ HDstrncpy(full_path, cwdpath, cwdlen + 1);
#ifdef H5_VMS
/* If the file name contains relative path, cut off the beginning bracket. Also cut off the
* ending bracket of CWDPATH to combine the full path name. i.g.
@@ -759,15 +766,16 @@ H5_build_extpath(const char *name, char **extpath/*out*/)
*/
if(new_name[0] == '[') {
char *tmp = new_name;
+
full_path[cwdlen - 1] = '\0';
HDstrcat(full_path, ++tmp);
} /* end if */
else
- HDstrcat(full_path, new_name);
+ HDstrncat(full_path, new_name, HDstrlen(new_name));
#else
if(!CHECK_DELIMITER(cwdpath[cwdlen - 1]))
- HDstrcat(full_path, DIR_SEPS);
- HDstrcat(full_path, new_name);
+ HDstrncat(full_path, DIR_SEPS, HDstrlen(DIR_SEPS));
+ HDstrncat(full_path, new_name, HDstrlen(new_name));
#endif
} /* end if */
} /* end else */
diff --git a/test/accum.c b/test/accum.c
index e4c1bd8..488b866 100644
--- a/test/accum.c
+++ b/test/accum.c
@@ -470,8 +470,11 @@ test_free(void)
if(HDmemcmp(expect + 76, rbuf, 116 * sizeof(int32_t)) != 0) TEST_ERROR;
HDfree(wbuf);
+ wbuf = NULL;
HDfree(rbuf);
+ rbuf = NULL;
HDfree(expect);
+ expect = NULL;
if(accum_reset() < 0) FAIL_STACK_ERROR;
@@ -480,9 +483,12 @@ test_free(void)
return 0;
error:
- HDfree(wbuf);
- HDfree(rbuf);
- HDfree(expect);
+ if(wbuf)
+ HDfree(wbuf);
+ if(rbuf)
+ HDfree(rbuf);
+ if(expect)
+ HDfree(expect);
return 1;
} /* test_free */
@@ -1646,7 +1652,7 @@ unsigned
test_random_write(void)
{
uint8_t *wbuf, *rbuf; /* Buffers for reading & writing */
- unsigned long seed = 0; /* Random # seed */
+ unsigned seed = 0; /* Random # seed */
size_t *off; /* Offset of buffer segments to write */
size_t *len; /* Size of buffer segments to write */
size_t cur_off; /* Current offset */
@@ -1667,10 +1673,10 @@ test_random_write(void)
TESTING("random writes to accumulator");
/* Choose random # seed */
- seed = (unsigned long)HDtime(NULL);
+ seed = (unsigned)HDtime(NULL);
#ifdef QAK
-/* seed = (unsigned long)1155438845; */
-HDfprintf(stderr, "Random # seed was: %lu\n", seed);
+/* seed = (unsigned)1155438845; */
+HDfprintf(stderr, "Random # seed was: %u\n", seed);
#endif /* QAK */
HDsrandom(seed);
@@ -1762,7 +1768,7 @@ error:
HDfree(off);
HDfree(len);
- HDfprintf(stderr, "Random # seed was: %lu\n", seed);
+ HDfprintf(stderr, "Random # seed was: %u\n", seed);
return 1;
} /* end test_random_write() */
diff --git a/test/stab.c b/test/stab.c
index a42ee5e..48b58b1 100644
--- a/test/stab.c
+++ b/test/stab.c
@@ -539,7 +539,7 @@ long_compact(hid_t fapl2)
hid_t fid = (-1); /* File ID */
hid_t gid = (-1); /* Group ID */
hid_t gid2 = (-1); /* Group ID */
- char *objname; /* Object name */
+ char *objname = NULL; /* Object name */
char filename[NAME_BUF_SIZE];
h5_stat_size_t empty_size; /* Size of an empty file */
h5_stat_size_t file_size; /* Size of each file created */
@@ -557,7 +557,7 @@ long_compact(hid_t fapl2)
if((empty_size = h5_get_file_size(filename, fapl2)) < 0) TEST_ERROR
/* Construct very long object name template */
- if((objname = (char *)HDmalloc((size_t)(LONG_COMPACT_LENGTH + 1))) == NULL) TEST_ERROR
+ if(NULL == (objname = (char *)HDmalloc((size_t)(LONG_COMPACT_LENGTH + 1)))) TEST_ERROR
HDmemset(objname, 'a', (size_t)LONG_COMPACT_LENGTH);
objname[LONG_COMPACT_LENGTH] = '\0';
@@ -620,6 +620,7 @@ long_compact(hid_t fapl2)
/* Free object name */
HDfree(objname);
+ objname = NULL;
/* Close top group */
if(H5Gclose(gid) < 0) TEST_ERROR
@@ -645,6 +646,10 @@ error:
H5Gclose(gid);
H5Fclose(fid);
} H5E_END_TRY;
+
+ if(objname)
+ HDfree(objname);
+
return 1;
} /* end long_compact() */
diff --git a/test/vfd.c b/test/vfd.c
index ca354d9..b85c054 100644
--- a/test/vfd.c
+++ b/test/vfd.c
@@ -28,17 +28,20 @@
#define FAMILY_SIZE2 (5*KB)
#define MULTI_SIZE 128
#define CORE_INCREMENT (4*KB)
+#define DSET1_NAME "dset1"
+#define DSET1_DIM1 1024
+#define DSET1_DIM2 32
+#define DSET3_NAME "dset3"
-/*Macros for Direct VFD*/
+/* Macros for Direct VFD */
+#ifdef H5_HAVE_DIRECT
#define MBOUNDARY 512
#define FBSIZE (4*KB)
#define CBSIZE (8*KB)
#define THRESHOLD 1
-#define DSET1_NAME "dset1"
-#define DSET1_DIM1 1024
-#define DSET1_DIM2 32
#define DSET2_NAME "dset2"
#define DSET2_DIM 4
+#endif /* H5_HAVE_DIRECT */
const char *FILENAME[] = {
"sec2_file", /*0*/
@@ -165,7 +168,7 @@ test_direct(void)
size_t mbound;
size_t fbsize;
size_t cbsize;
- int *points, *check, *p1, *p2;
+ int *points = NULL, *check = NULL, *p1, *p2;
int wdata2[DSET2_DIM] = {11,12,13,14};
int rdata2[DSET2_DIM];
int i, j, n;
@@ -189,10 +192,10 @@ test_direct(void)
if(H5Pget_fapl_direct(fapl, &mbound, &fbsize, &cbsize) < 0)
TEST_ERROR;
if(mbound != MBOUNDARY || fbsize != FBSIZE || cbsize != CBSIZE)
- TEST_ERROR;
+ TEST_ERROR;
if(H5Pset_alignment(fapl, (hsize_t)THRESHOLD, (hsize_t)FBSIZE) < 0)
- TEST_ERROR;
+ TEST_ERROR;
H5E_BEGIN_TRY {
file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
@@ -235,17 +238,16 @@ test_direct(void)
/* Allocate aligned memory for data set 1. For data set 1, everything is aligned including
* memory address, size of data, and file address. */
- if(posix_memalign(&points, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0)
+ if(0 != HDposix_memalign(&points, (size_t)FBSIZE, (size_t)(DSET1_DIM1 * DSET1_DIM2 * sizeof(int))))
TEST_ERROR;
-
- if(posix_memalign(&check, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0)
+ if(0 != HDposix_memalign(&check, (size_t)FBSIZE, (size_t)(DSET1_DIM1 * DSET1_DIM2 * sizeof(int))))
TEST_ERROR;
/* Initialize the dset1 */
p1 = points;
for(i = n = 0; i < DSET1_DIM1; i++)
- for(j = 0; j < DSET1_DIM2; j++)
- *p1++ = n++;
+ for(j = 0; j < DSET1_DIM2; j++)
+ *p1++ = n++;
/* Create the data space1 */
dims1[0] = DSET1_DIM1;
@@ -275,13 +277,13 @@ test_direct(void)
p1 = points;
p2 = check;
for(i = 0; i < DSET1_DIM1; i++)
- for(j = 0; j < DSET1_DIM2; j++)
- if(*p1++ != *p2++) {
- H5_FAILED();
- printf(" Read different values than written in data set 1.\n");
- printf(" At index %d,%d\n", i, j);
- TEST_ERROR;
- } /* end if */
+ for(j = 0; j < DSET1_DIM2; j++)
+ if(*p1++ != *p2++) {
+ H5_FAILED();
+ printf(" Read different values than written in data set 1.\n");
+ printf(" At index %d,%d\n", i, j);
+ TEST_ERROR;
+ } /* end if */
/* Create the data space2. For data set 2, memory address and data size are not aligned. */
dims2[0] = DSET2_DIM;
@@ -308,12 +310,12 @@ test_direct(void)
/* Check that the values read are the same as the values written */
for(i = 0; i < DSET2_DIM; i++)
- if(wdata2[i] != rdata2[i]) {
- H5_FAILED();
- printf(" Read different values than written in data set 2.\n");
- printf(" At index %d\n", i);
+ if(wdata2[i] != rdata2[i]) {
+ H5_FAILED();
+ printf(" Read different values than written in data set 2.\n");
+ printf(" At index %d\n", i);
TEST_ERROR;
- } /* end if */
+ } /* end if */
if(H5Sclose(space1) < 0)
TEST_ERROR;
@@ -325,10 +327,10 @@ test_direct(void)
TEST_ERROR;
if(H5Fclose(file) < 0)
TEST_ERROR;
- if(points)
- free(points);
- if(check)
- free(check);
+ HDassert(points);
+ HDfree(points);
+ HDassert(check);
+ HDfree(check);
h5_cleanup(FILENAME, fapl);
PASSED();
@@ -336,13 +338,19 @@ test_direct(void)
error:
H5E_BEGIN_TRY {
- H5Pclose (fapl);
+ H5Pclose(fapl);
H5Sclose(space1);
H5Dclose(dset1);
H5Sclose(space2);
H5Dclose(dset2);
H5Fclose(file);
} H5E_END_TRY;
+
+ if(points)
+ HDfree(points);
+ if(check)
+ HDfree(check);
+
return -1;
#endif /*H5_HAVE_DIRECT*/
}
@@ -368,7 +376,7 @@ test_core(void)
char filename[1024];
void *fhandle=NULL;
hsize_t file_size;
- int *points, *check, *p1, *p2;
+ int *points = NULL, *check = NULL, *p1, *p2;
hid_t dset1=-1, space1=-1;
hsize_t dims1[2];
int i, j, n;
@@ -427,14 +435,16 @@ test_core(void)
TEST_ERROR;
/* Allocate memory for data set. */
- points=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int));
- check=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int));
+ if(NULL == (points = (int *)HDmalloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int))))
+ TEST_ERROR;
+ if(NULL == (check = (int *)HDmalloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int))))
+ TEST_ERROR;
/* Initialize the dset1 */
p1 = points;
for(i = n = 0; i < DSET1_DIM1; i++)
- for(j = 0; j < DSET1_DIM2; j++)
- *p1++ = n++;
+ for(j = 0; j < DSET1_DIM2; j++)
+ *p1++ = n++;
/* Create the data space1 */
dims1[0] = DSET1_DIM1;
@@ -464,13 +474,13 @@ test_core(void)
p1 = points;
p2 = check;
for(i = 0; i < DSET1_DIM1; i++)
- for(j = 0; j < DSET1_DIM2; j++)
- if(*p1++ != *p2++) {
- H5_FAILED();
- printf(" Read different values than written in data set 1.\n");
- printf(" At index %d,%d\n", i, j);
- TEST_ERROR;
- } /* end if */
+ for(j = 0; j < DSET1_DIM2; j++)
+ if(*p1++ != *p2++) {
+ H5_FAILED();
+ printf(" Read different values than written in data set 1.\n");
+ printf(" At index %d,%d\n", i, j);
+ TEST_ERROR;
+ } /* end if */
if(H5Dclose(dset1) < 0)
TEST_ERROR;
@@ -501,10 +511,10 @@ test_core(void)
TEST_ERROR;
/* Reallocate memory for reading buffer. */
- if(check)
- free(check);
-
- check = (int*)malloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int));
+ HDassert(check);
+ HDfree(check);
+ if(NULL == (check = (int *)HDmalloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int))))
+ TEST_ERROR;
/* Read the data back from dset1 */
if(H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0)
@@ -514,13 +524,13 @@ test_core(void)
p1 = points;
p2 = check;
for(i = 0; i < DSET1_DIM1; i++)
- for(j = 0; j < DSET1_DIM2; j++)
- if(*p1++ != *p2++) {
- H5_FAILED();
- printf(" Read different values than written in data set 1.\n");
- printf(" At index %d,%d\n", i, j);
- TEST_ERROR;
- } /* end if */
+ for(j = 0; j < DSET1_DIM2; j++)
+ if(*p1++ != *p2++) {
+ H5_FAILED();
+ printf(" Read different values than written in data set 1.\n");
+ printf(" At index %d,%d\n", i, j);
+ TEST_ERROR;
+ } /* end if */
/* Check file size API */
if(H5Fget_filesize(file, &file_size) < 0)
@@ -537,10 +547,10 @@ test_core(void)
TEST_ERROR;
if(H5Fclose(file) < 0)
TEST_ERROR;
- if(points)
- free(points);
- if(check)
- free(check);
+ HDassert(points);
+ HDfree(points);
+ HDassert(check);
+ HDfree(check);
h5_cleanup(FILENAME, fapl);
@@ -549,9 +559,15 @@ test_core(void)
error:
H5E_BEGIN_TRY {
- H5Pclose (fapl);
+ H5Pclose(fapl);
H5Fclose(file);
} H5E_END_TRY;
+
+ if(points)
+ HDfree(points);
+ if(check)
+ HDfree(check);
+
return -1;
}
@@ -579,27 +595,30 @@ test_family_opens(char *fname, hid_t fa_pl)
int i;
/* Case 1: reopen file with 1st member file name and default property list */
- sprintf(first_name, fname, 0);
+ HDsnprintf(first_name, sizeof(first_name), fname, 0);
H5E_BEGIN_TRY {
- file=H5Fopen(first_name, H5F_ACC_RDWR, H5P_DEFAULT);
+ file = H5Fopen(first_name, H5F_ACC_RDWR, H5P_DEFAULT);
} H5E_END_TRY;
- if(file >= 0) TEST_ERROR
+ if(file >= 0)
+ TEST_ERROR
/* Case 2: reopen file with correct name template but default property list */
H5E_BEGIN_TRY {
- file=H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT);
+ file = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT);
} H5E_END_TRY;
- if(file >= 0) TEST_ERROR
+ if(file >= 0)
+ TEST_ERROR
/* Case 3: reopen file with wrong member size */
if(H5Pset_fapl_family(fa_pl, (hsize_t)128, H5P_DEFAULT) < 0)
TEST_ERROR;
H5E_BEGIN_TRY {
- file=H5Fopen(fname, H5F_ACC_RDWR, fa_pl);
+ file = H5Fopen(fname, H5F_ACC_RDWR, fa_pl);
} H5E_END_TRY;
- if(file >= 0) TEST_ERROR
+ if(file >= 0)
+ TEST_ERROR
/* Case 4: reopen file with wrong name template */
HDstrcpy(wrong_name, fname);
@@ -613,9 +632,10 @@ test_family_opens(char *fname, hid_t fa_pl)
TEST_ERROR;
H5E_BEGIN_TRY {
- file=H5Fopen(wrong_name, H5F_ACC_RDWR, fa_pl);
+ file = H5Fopen(wrong_name, H5F_ACC_RDWR, fa_pl);
} H5E_END_TRY;
- if(file >= 0) TEST_ERROR
+ if(file >= 0)
+ TEST_ERROR
return 0;
@@ -704,44 +724,44 @@ test_family(void)
if((dset=H5Dcreate2(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
- for(i=0; i<FAMILY_NUMBER; i++)
- for(j=0; j<FAMILY_SIZE; j++)
- buf[i][j] = i*10000+j;
+ for(i = 0; i < FAMILY_NUMBER; i++)
+ for(j = 0; j < FAMILY_SIZE; j++)
+ buf[i][j] = (int)((i * 10000) + j);
if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
TEST_ERROR;
/* check file handle API */
- if((fapl2=H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ if((fapl2 = H5Pcreate(H5P_FILE_ACCESS)) < 0)
TEST_ERROR;
if(H5Pset_family_offset(fapl2, (hsize_t)0) < 0)
TEST_ERROR;
if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle) < 0)
TEST_ERROR;
- if(*fhandle<0)
+ if(*fhandle < 0)
TEST_ERROR;
if(H5Pset_family_offset(fapl2, (hsize_t)(FAMILY_SIZE*2)) < 0)
TEST_ERROR;
if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle2) < 0)
TEST_ERROR;
- if(*fhandle2<0)
+ if(*fhandle2 < 0)
TEST_ERROR;
/* Check file size API */
if(H5Fget_filesize(file, &file_size) < 0)
TEST_ERROR;
- /* Some data has been written. The file size should be bigger(18KB+976
+ /* Some data has been written. The file size should be bigger (18KB+976)
* bytes if int size is 4 bytes) now. */
- if(sizeof(int)<=4) {
- if(file_size<18*KB || file_size>20*KB)
- TEST_ERROR;
- } else if(sizeof(int)>=8) {
- if(file_size<32*KB || file_size>40*KB)
- TEST_ERROR;
- }
+#if H5_SIZEOF_INT <= 4
+ if(file_size < (18 * KB) || file_size > (20 * KB))
+ TEST_ERROR;
+#elif H5_SIZEOF_INT >= 8
+ if(file_size < (32 * KB) || file_size > (40 * KB))
+ TEST_ERROR;
+#endif
if(H5Sclose(space) < 0)
TEST_ERROR;
@@ -761,7 +781,7 @@ test_family(void)
if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0)
TEST_ERROR;
- if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
+ if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
if(H5Fclose(file) < 0)
@@ -829,13 +849,13 @@ test_family_compat(void)
* Since we're going to open the files with write mode, this protects the original
* files.
*/
- sprintf(newname_individual, newname, counter);
- sprintf(pathname_individual, pathname, counter);
+ HDsnprintf(newname_individual, sizeof(newname_individual), newname, counter);
+ HDsnprintf(pathname_individual, sizeof(pathname_individual), pathname, counter);
- while (h5_make_local_copy(pathname_individual, newname_individual) >= 0) {
+ while(h5_make_local_copy(pathname_individual, newname_individual) >= 0) {
counter++;
- sprintf(newname_individual, newname, counter);
- sprintf(pathname_individual, pathname, counter);
+ HDsnprintf(newname_individual, sizeof(newname_individual), newname, counter);
+ HDsnprintf(pathname_individual, sizeof(pathname_individual), pathname, counter);
}
/* Make sure we can open the file. Use the read and write mode to flush the
@@ -888,7 +908,7 @@ error:
* reopening multi file.
*
* Return: Success: 0
- * Failure: 1
+ * Failure: -1
*
* Programmer: Raymond Lu
* Thursday, May 19, 2005
@@ -903,14 +923,14 @@ test_multi_opens(char *fname)
char sf_name[1024]; /*name string "multi_file-s.h5"*/
/* Case: reopen with the name of super file and default property list */
- sprintf(super_name, "%%s-%c.h5", 's');
- sprintf(sf_name, super_name, fname);
+ HDsnprintf(super_name, sizeof(super_name), "%%s-%c.h5", 's');
+ HDsnprintf(sf_name, sizeof(sf_name), super_name, fname);
H5E_BEGIN_TRY {
- file=H5Fopen(sf_name, H5F_ACC_RDWR, H5P_DEFAULT);
+ file = H5Fopen(sf_name, H5F_ACC_RDWR, H5P_DEFAULT);
} H5E_END_TRY;
- return 0;
+ return(file >= 0 ? -1 : 0);
}
@@ -999,11 +1019,11 @@ test_multi(void)
TEST_ERROR;
/* Reopen the file */
- if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
+ if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
/* Create and write data set */
- if((space=H5Screate_simple(2, dims, NULL)) < 0)
+ if((space = H5Screate_simple(2, dims, NULL)) < 0)
TEST_ERROR;
/* Retrieve the access property list... */
@@ -1146,19 +1166,16 @@ error:
static herr_t
test_multi_compat(void)
{
- hid_t file=(-1), fapl, fapl2=(-1), dset=(-1), space=(-1);
- hid_t access_fapl = -1;
+ hid_t file=(-1), fapl, dset=(-1), space=(-1);
char newname[1024];
char filename_s[1024], newname_s[1024];
char filename_r[1024], newname_r[1024];
- int *fhandle2=NULL, *fhandle=NULL;
H5FD_mem_t mt, memb_map[H5FD_MEM_NTYPES];
hid_t memb_fapl[H5FD_MEM_NTYPES];
haddr_t memb_addr[H5FD_MEM_NTYPES];
const char *memb_name[H5FD_MEM_NTYPES];
char sv[H5FD_MEM_NTYPES][32];
hsize_t dims[2]={MULTI_SIZE, MULTI_SIZE};
- char dname[]="dataset2";
int i, j;
int buf[MULTI_SIZE][MULTI_SIZE];
@@ -1238,7 +1255,7 @@ test_multi_compat(void)
if((space=H5Screate_simple(2, dims, NULL)) < 0)
TEST_ERROR;
- if((dset=H5Dcreate2(file, DSET2_NAME, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ if((dset=H5Dcreate2(file, DSET3_NAME, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
for(i=0; i<MULTI_SIZE; i++)
@@ -1267,7 +1284,7 @@ test_multi_compat(void)
if(H5Dclose(dset) < 0)
TEST_ERROR;
- if((dset = H5Dopen2(file, DSET2_NAME, H5P_DEFAULT)) < 0)
+ if((dset = H5Dopen2(file, DSET3_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR;
if(H5Dclose(dset) < 0)
@@ -1315,13 +1332,13 @@ test_log(void)
int *fhandle = NULL;
hsize_t file_size = 0;
unsigned int flags = H5FD_LOG_ALL;
- size_t buf_size = 0;
+ size_t buf_size = 4 * KB;
TESTING("LOG file driver");
/* Set property list and file name for log driver. */
fapl = h5_fileaccess();
- if(H5Pset_fapl_log(fapl, LOG_FILENAME, 0, buf_size) < 0)
+ if(H5Pset_fapl_log(fapl, LOG_FILENAME, flags, buf_size) < 0)
TEST_ERROR;
h5_fixname(FILENAME[6], fapl, filename, sizeof filename);
diff --git a/tools/h5jam/h5unjam.c b/tools/h5jam/h5unjam.c
index c304045..18b5f11 100644
--- a/tools/h5jam/h5unjam.c
+++ b/tools/h5jam/h5unjam.c
@@ -43,14 +43,14 @@ static const char *s_opts = "hu:i:o:d:V";
static struct long_options l_opts[] = {
{ "help", no_arg, 'h' },
{ "hel", no_arg, 'h' },
- {"i", require_arg, 'i'}, /* input file */
- {"u", require_arg, 'u'}, /* user block file */
- {"o", require_arg, 'o'}, /* output file */
- {"delete", no_arg, 'd'}, /* delete ub */
- {"delet", no_arg, 'd'},
- {"dele", no_arg, 'd'},
- {"del", no_arg, 'd'},
- {"de", no_arg, 'd'},
+ {"i", require_arg, 'i'}, /* input file */
+ {"u", require_arg, 'u'}, /* user block file */
+ {"o", require_arg, 'o'}, /* output file */
+ {"delete", no_arg, 'd'}, /* delete ub */
+ {"delet", no_arg, 'd'},
+ {"dele", no_arg, 'd'},
+ {"del", no_arg, 'd'},
+ {"de", no_arg, 'd'},
{ NULL, 0, '\0' }
};
@@ -123,86 +123,69 @@ usage(const char *prog)
}
/*-------------------------------------------------------------------------
- * Function: leave
- *
- * Purpose: Shutdown and call exit()
- *
- * Return: Does not return
- *
- *-------------------------------------------------------------------------
- */
-static void
-leave(int ret)
-{
- if (ub_file)
- HDfree (ub_file);
- if (input_file)
- HDfree (input_file);
- if (output_file)
- HDfree (output_file);
-
- h5tools_close();
-
- HDexit(ret);
-}
-
-/*-------------------------------------------------------------------------
* Function: parse_command_line
*
* Purpose: Parse the command line for the h5dumper.
*
- * Return: Success:
+ * Return: Success: EXIT_SUCCESS;
*
- * Failure: Exits program with EXIT_FAILURE value.
- *
- * Programmer:
- *
- * Modifications:
+ * Failure: Exits function with EXIT_FAILURE value.
*
*-------------------------------------------------------------------------
*/
-
-static void
+static int
parse_command_line(int argc, const char *argv[])
{
int opt = FALSE;
/* parse command line options */
while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
- switch ((char) opt) {
- case 'o':
- output_file = HDstrdup (opt_arg);
- break;
- case 'i':
- input_file = HDstrdup (opt_arg);
- break;
- case 'u':
- ub_file = HDstrdup (opt_arg);
- break;
- case 'd':
- do_delete = TRUE;
- break;
- case 'h':
- usage(h5tools_getprogname());
- leave(EXIT_SUCCESS);
- case 'V':
- print_version(h5tools_getprogname());
- leave(EXIT_SUCCESS);
- case '?':
- default:
- usage(h5tools_getprogname());
- leave(EXIT_FAILURE);
+ switch((char)opt) {
+ case 'o':
+ output_file = HDstrdup(opt_arg);
+ break;
+
+ case 'i':
+ input_file = HDstrdup(opt_arg);
+ break;
+
+ case 'u':
+ ub_file = HDstrdup(opt_arg);
+ break;
+
+ case 'd':
+ do_delete = TRUE;
+ break;
+
+ case 'h':
+ usage(h5tools_getprogname());
+ h5tools_setstatus(EXIT_SUCCESS);
+ goto done;
+
+ case 'V':
+ print_version (h5tools_getprogname());
+ h5tools_setstatus(EXIT_SUCCESS);
+ goto done;
+
+ case '?':
+ default:
+ usage(h5tools_getprogname());
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
}
}
- /* check for file name to be processed */
-/*
- if (argc <= opt_ind+2) {
- error_msg("missing file name\n");
- usage(h5tools_getprogname());
- HDexit(EXIT_FAILURE);
- }
-*/
+ return EXIT_SUCCESS;
+
+done:
+ if(input_file)
+ HDfree(input_file);
+ if(output_file)
+ HDfree(output_file);
+ if(ub_file)
+ HDfree(ub_file);
+
+ return EXIT_FAILURE;
}
/*-------------------------------------------------------------------------
@@ -246,13 +229,15 @@ main(int argc, const char *argv[])
/* Initialize h5tools lib */
h5tools_init();
- parse_command_line(argc, argv);
+ if(EXIT_FAILURE == parse_command_line(argc, argv))
+ goto done;
if (input_file == NULL) {
/* no user block */
error_msg("missing arguemnt for HDF5 file input.\n");
help_ref_msg(stderr);
- leave (EXIT_FAILURE);
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
}
testval = H5Fis_hdf5(input_file);
@@ -286,8 +271,10 @@ main(int argc, const char *argv[])
goto done;
}
- H5Pclose(plist);
- H5Fclose(ifile);
+ status = H5Pclose(plist);
+ HDassert(status >= 0);
+ status = H5Fclose(ifile);
+ HDassert(status >= 0);
if (usize == 0) {
/* no user block to remove: message? */
@@ -320,7 +307,7 @@ main(int argc, const char *argv[])
if (ub_file == NULL) {
/* write to sdtout */
- ufid = HDdup(1);
+ ufid = STDOUT_FILENO;
}
else {
ufid = HDopen(ub_file,O_WRONLY|O_CREAT|O_TRUNC, 0644 );
@@ -371,17 +358,25 @@ main(int argc, const char *argv[])
}
done:
- if (ub_file) {
- HDfree (ub_file);
- if (ufid >= 0) HDclose(ufid);
+ if(input_file)
+ HDfree(input_file);
+ if(output_file)
+ HDfree(output_file);
+ if(ub_file) {
+ HDfree(ub_file);
+ if(ufid >= 0)
+ status = HDclose(ufid);
+ HDassert(status >= 0);
}
- if (input_file)
- HDfree (input_file);
- if (output_file)
- HDfree (output_file);
- if (h5fid >= 0) HDclose(h5fid);
- if (ifid >= 0) HDclose(ifid);
+ if(h5fid >= 0) {
+ status = HDclose(h5fid);
+ HDassert(status >= 0);
+ }
+ if(ifid >= 0) {
+ status = HDclose(ifid);
+ HDassert(status >= 0);
+ }
return h5tools_getstatus();
}
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 66c0e64..0d9bc15 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -30,10 +30,6 @@
#include "h5tools_utils.h"
#include "H5private.h"
-#define SANITY_CHECK
-
-#define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z))
-
/* global variables */
hid_t H5tools_ERR_STACK_g = 0;
hid_t H5tools_ERR_CLS_g = -1;
@@ -1122,7 +1118,6 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
while(block_index > 0) {
size_t bytes_in = 0; /* # of bytes to write */
size_t bytes_wrote = 0; /* # of bytes written */
- size_t item_size = size; /* size of items in bytes */
if(block_index > sizeof(size_t))
bytes_in = sizeof(size_t);
@@ -1168,16 +1163,21 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
break;
case H5T_COMPOUND:
{
- unsigned j;
- hid_t memb;
+ int snmembs;
unsigned nmembs;
- size_t offset;
- nmembs = H5Tget_nmembers(tid);
+ if((snmembs = H5Tget_nmembers(tid)) < 0)
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers of compound failed");
+ nmembs = (unsigned)snmembs;
for (block_index = 0; block_index < block_nelmts; block_index++) {
+ unsigned j;
+
mem = ((unsigned char*)_mem) + block_index * size;
for (j = 0; j < nmembs; j++) {
+ hid_t memb;
+ size_t offset;
+
offset = H5Tget_member_offset(tid, j);
memb = H5Tget_member_type(tid, j);
@@ -1192,7 +1192,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
case H5T_ARRAY:
{
int k, ndims;
- hsize_t i, dims[H5S_MAX_RANK], temp_nelmts, nelmts;
+ hsize_t dims[H5S_MAX_RANK], temp_nelmts, nelmts;
hid_t memb;
/* get the array's base datatype for each element */
@@ -1219,7 +1219,6 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
break;
case H5T_VLEN:
{
- unsigned int i;
hsize_t nelmts;
hid_t memb;
@@ -1305,10 +1304,9 @@ render_bin_output_region_data_blocks(hid_t region_id, FILE *stream,
hsize_t *start = NULL;
hsize_t *count = NULL;
hsize_t numelem;
- hsize_t numindex;
hsize_t total_size[H5S_MAX_RANK];
int jndx;
- int type_size;
+ size_t type_size;
hid_t mem_space = -1;
void *region_buf = NULL;
int blkndx;
@@ -1399,15 +1397,17 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id,
FILE *stream, hid_t container)
{
HERR_INIT(hbool_t, TRUE)
- hssize_t nblocks;
+ hssize_t snblocks;
+ hsize_t nblocks;
hsize_t alloc_size;
- hsize_t *ptdata = NULL;
+ hsize_t *ptdata;
int ndims;
hid_t dtype;
hid_t type_id;
- if((nblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
+ if((snblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed");
+ nblocks = (hsize_t)snblocks;
/* Print block information */
if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0)
@@ -1463,13 +1463,12 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id,
* hssize_t npoints is the number of points in the region
*-------------------------------------------------------------------------
*/
-int
+static int
render_bin_output_region_data_points(hid_t region_space, hid_t region_id,
FILE *stream, hid_t container,
- int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata)
+ int ndims, hid_t type_id, hssize_t npoints)
{
hsize_t *dims1 = NULL;
- int jndx;
int type_size;
hid_t mem_space = -1;
void *region_buf = NULL;
@@ -1525,8 +1524,6 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id,
{
HERR_INIT(hbool_t, TRUE)
hssize_t npoints;
- hsize_t alloc_size;
- hsize_t *ptdata;
int ndims;
hid_t dtype;
hid_t type_id;
@@ -1538,15 +1535,6 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id,
if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0)
H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
- alloc_size = npoints * ndims * sizeof(ptdata[0]);
- HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/
- if(NULL == (ptdata = (hsize_t *)HDmalloc((size_t) alloc_size)))
- HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "Could not allocate buffer for ptdata");
-
- H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t);
- if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0)
- HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Sget_select_elem_pointlist failed");
-
if((dtype = H5Dget_type(region_id)) < 0)
HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Dget_type failed");
@@ -1554,11 +1542,9 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id,
HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Tget_native_type failed");
render_bin_output_region_data_points(region_space, region_id,
- stream, container, ndims, type_id, npoints, ptdata);
+ stream, container, ndims, type_id, npoints);
done:
- HDfree(ptdata);
-
if(H5Tclose(type_id) < 0)
HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed");