summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2013-02-02 01:53:32 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2013-02-02 01:53:32 (GMT)
commita3e98d0e36a0fbd6caae0a4a83863a78c2e25f50 (patch)
tree14e6c86e83d0b65e7033f9d31b0163404b41e36d /src
parent5140343f45312d4d2e486e6cc7645c7bc42b1267 (diff)
downloadhdf5-a3e98d0e36a0fbd6caae0a4a83863a78c2e25f50.zip
hdf5-a3e98d0e36a0fbd6caae0a4a83863a78c2e25f50.tar.gz
hdf5-a3e98d0e36a0fbd6caae0a4a83863a78c2e25f50.tar.bz2
[svn-r23219] Description:
Bring reviewed changes from Coverity branch back to trunk (QK & JK): r20457: Coverity issue 691: return of H5duo could be negative. Fixed by using STDOUT_FILENO and redesign parse_command_line and main to cleanup file allocations. The output_file var is null when using stdout. In cleanup do not close output_file if NULL. r20510: Initialize ufid = -1 and predicate HDclose call on ufid != -1 r20511: Purpose: Fix coverity issue 1715 Description: Free "file" and nested data on failure in H5FD_core_open. r20512: Initialize ifid = -1 and predicate HDclose call on ifid != -1 r20514: Initialize h5fid = -1 and predicate HDclose call on h5fid != -1 r20516: Added else branch to the if (ret_value < 0) check. r20522: Addressed coverity issues 930-933, 850, 836, 835, 1307. All minor potential buffer overwrite bugs, or coverity errors. Fixed by replacing strcpy and sprintf with strncpy and snprintf. r20523: fixed coverity issues 68, 1120, 1116i r20524: Check H5Z_SZIP->encoder_present < 1 assuming 0 represents absence. r20601: Purpose: Fix coverity issues 1703-1705 Description: Modified the cleanup code in test_free in accum.c to reset allocated buffers to NULL after they are freed, and modified the error cleanup code to check if these buffers are NULL before freeing them. Also fixed some unrelated warnings in accum.c. r20602: Use HDsnprintf and HDstrncat r20603: Purpose: Fix coverity issues 808-809 Description: Modified test_core in vfd.c to check the returns from malloc, and keep track of whether points and check are allocated by setting them to NULL when they are not. Added code to free points and check on error if they are not NULL. Also fixed unrelated warnings in vfd.c. r20604: Use HDstrncpy. r20605: Use HDstrncpy and HDstrncat. r20606: Purpose: Fix coverity issue 807 Description: Modified long_compact in stab.c to keep track of whether objname is allocated by setting it to NULL when it is not. Added code to free objname on error if it is not NULL. r20607: Changed string function calls to use versions that specify the string length to fix coverity issues 832 and 839. Tested on: Mac OSX/64 10.8.2 (amazon) (Too minor to require h5committest)
Diffstat (limited to 'src')
-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
6 files changed, 378 insertions, 333 deletions
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 */