summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2014-02-21 16:59:33 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2014-02-21 16:59:33 (GMT)
commit86d6651b44ce710bea66d7893d97673ead588268 (patch)
tree773bc8d4e93a3455268cad323c90d80d0906a4f0 /src
parent456507476f05e133be004e91d729c93c07a06765 (diff)
downloadhdf5-86d6651b44ce710bea66d7893d97673ead588268.zip
hdf5-86d6651b44ce710bea66d7893d97673ead588268.tar.gz
hdf5-86d6651b44ce710bea66d7893d97673ead588268.tar.bz2
[svn-r24728] Description:
Bring r24726 & r24727 from trunk to 1.8 branch: Description: Revert some earlier usage of strncpy, which was incorrect. Bring Coverity changes from branch back to trunk: r20821: Use HDstrncpy. --gh (Fixed already, with strdup) r20822: (Not merged, incorrect use of HDstrncpy()) r20823: (Not merged, incorrect use of HDstrncpy()) r20824: Maintenance: Bug fix: addressed CID 666. Value stored at *expression_len should be used in the call to HD5packFstring to avoid overflow (and unnecessary arithmetic calculation and casting) r20825: Issue 642: Added check for error and handler with print to stderr and exit. r20826: Undo revision 20818, as that issue has already been fixed in the 1.8 branch and trunk (but not coverity branch) r20827: (Not merged, incorrect use of HDstrncpy()) r20828: Use HDstrncpy. --gh (Corrected use of strncpy()) r20829: Check return of H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) and if error set trgbuf[0] to 0. Check if H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname) was successful and allow print. Otherwise filename and objname are not created. (init those to NULL) r20830: resolved coverity issues 939, 940, 941, 944, and 947. all were complaints about use of sprintf, and in all cases, the buffers used were large enough for all eventualities. Resolved issue by replacing calls to sprintf with calls to snprintf. r20831: Maintenance: Addressed CID 852 Replaced sprintf with snprintf r20832: Purpose: Fix valgrind issues with hl/examples/ex_image2 Description: Modified hl/examples/ex_image2 to free global "gbuf" before exit. Tested on: Mac OSX/64 10.9.1 (amaon) w/C++, FORTRAN & Threadsafety (too minor to require h5committest)
Diffstat (limited to 'src')
-rw-r--r--src/H5HGdbg.c74
-rw-r--r--src/H5HLdbg.c26
-rw-r--r--src/H5Lexternal.c12
-rw-r--r--src/H5Oattr.c20
-rw-r--r--src/H5Oefl.c11
-rw-r--r--src/H5system.c24
6 files changed, 92 insertions, 75 deletions
diff --git a/src/H5HGdbg.c b/src/H5HGdbg.c
index 74044cb..16d8c49 100644
--- a/src/H5HGdbg.c
+++ b/src/H5HGdbg.c
@@ -91,9 +91,8 @@ H5HG_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
unsigned u, nused, maxobj;
unsigned j, k;
H5HG_heap_t *h = NULL;
- char buf[64];
uint8_t *p = NULL;
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
@@ -107,66 +106,69 @@ H5HG_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
if(NULL == (h = H5HG_protect(f, dxpl_id, addr, H5AC_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect global heap collection");
- fprintf(stream, "%*sGlobal Heap Collection...\n", indent, "");
- fprintf(stream, "%*s%-*s %d\n", indent, "", fwidth,
+ HDfprintf(stream, "%*sGlobal Heap Collection...\n", indent, "");
+ HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth,
"Dirty:",
(int)(h->cache_info.is_dirty));
- fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth,
"Total collection size in file:",
(unsigned long)(h->size));
- for (u=1, nused=0, maxobj=0; u<h->nused; u++) {
- if (h->obj[u].begin) {
+ for(u = 1, nused = 0, maxobj = 0; u < h->nused; u++)
+ if(h->obj[u].begin) {
nused++;
- if (u>maxobj) maxobj = u;
+ if (u>maxobj)
+ maxobj = u;
}
- }
- fprintf (stream, "%*s%-*s %u/%lu/", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s %u/%lu/", indent, "", fwidth,
"Objects defined/allocated/max:",
- nused, (unsigned long)h->nalloc);
+ nused,
+ (unsigned long)h->nalloc);
if(nused)
- fprintf(stream, "%u\n", maxobj);
+ HDfprintf(stream, "%u\n", maxobj);
else
- fprintf(stream, "NA\n");
+ HDfprintf(stream, "NA\n");
- fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth,
"Free space:",
(unsigned long)(h->obj[0].size));
- for (u=1; u<h->nused; u++) {
- if (h->obj[u].begin) {
- sprintf (buf, "Object %u", u);
- fprintf (stream, "%*s%s\n", indent, "", buf);
- fprintf (stream, "%*s%-*s %lu\n", indent+3, "", MIN(fwidth-3, 0),
+ for(u = 1; u < h->nused; u++)
+ if(h->obj[u].begin) {
+ char buf[64];
+
+ HDsnprintf(buf, sizeof(buf), "Object %u", u);
+ HDfprintf(stream, "%*s%s\n", indent, "", buf);
+ HDfprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MIN(fwidth - 3, 0),
"Obffset in block:",
(unsigned long)(h->obj[u].begin - h->chunk));
- fprintf (stream, "%*s%-*s %d\n", indent+3, "", MIN(fwidth-3, 0),
+ HDfprintf(stream, "%*s%-*s %d\n", indent + 3, "", MIN(fwidth - 3, 0),
"Reference count:",
h->obj[u].nrefs);
- fprintf (stream, "%*s%-*s %lu/%lu\n", indent+3, "",
- MIN(fwidth-3, 0),
+ HDfprintf(stream, "%*s%-*s %lu/%lu\n", indent + 3, "",
+ MIN(fwidth - 3, 0),
"Size of object body:",
(unsigned long)(h->obj[u].size),
(unsigned long)H5HG_ALIGN(h->obj[u].size));
- p = h->obj[u].begin + H5HG_SIZEOF_OBJHDR (f);
- for (j=0; j<h->obj[u].size; j+=16) {
- fprintf (stream, "%*s%04u: ", indent+6, "", j);
- for (k=0; k<16; k++) {
- if (8==k) fprintf (stream, " ");
- if (j+k<h->obj[u].size) {
- fprintf (stream, "%02x ", p[j+k]);
- } else {
+ p = h->obj[u].begin + H5HG_SIZEOF_OBJHDR(f);
+ for(j = 0; j < h->obj[u].size; j += 16) {
+ HDfprintf(stream, "%*s%04u: ", indent + 6, "", j);
+ for(k = 0; k < 16; k++) {
+ if(8 == k)
+ HDfprintf(stream, " ");
+ if(j + k < h->obj[u].size)
+ HDfprintf(stream, "%02x ", p[j + k]);
+ else
HDfputs(" ", stream);
- }
}
- for (k=0; k<16 && j+k<h->obj[u].size; k++) {
- if (8==k) fprintf (stream, " ");
- HDfputc(p[j+k]>' ' && p[j+k]<='~' ? p[j+k] : '.', stream);
+ for(k = 0; k < 16 && j + k < h->obj[u].size; k++) {
+ if(8 == k)
+ HDfprintf(stream, " ");
+ HDfputc(p[j + k]>' ' && p[j + k] <= '~' ? p[j + k] : '.', stream);
}
- fprintf (stream, "\n");
+ HDfprintf(stream, "\n");
}
}
- }
done:
if (h && H5AC_unprotect(f, dxpl_id, H5AC_GHEAP, addr, h, H5AC__NO_FLAGS_SET) < 0)
diff --git a/src/H5HLdbg.c b/src/H5HLdbg.c
index 29d5c82..4ac22b8 100644
--- a/src/H5HLdbg.c
+++ b/src/H5HLdbg.c
@@ -54,8 +54,8 @@ herr_t
H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int fwidth)
{
H5HL_t *h = NULL;
- int i, overlap, free_block;
- H5HL_free_t *freelist = NULL;
+ int free_block;
+ H5HL_free_t *freelist;
uint8_t *marker = NULL;
size_t amount_free = 0;
herr_t ret_value = SUCCEED; /* Return value */
@@ -72,8 +72,8 @@ H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int
if(NULL == (h = (H5HL_t *)H5HL_protect(f, dxpl_id, addr, H5AC_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap")
- fprintf(stream, "%*sLocal Heap...\n", indent, "");
- fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth,
+ HDfprintf(stream, "%*sLocal Heap...\n", indent, "");
+ HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth,
"Header size (in bytes):",
(unsigned long)h->prfx_size);
HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
@@ -90,34 +90,36 @@ H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int
if(NULL == (marker = (uint8_t *)H5MM_calloc(h->dblk_size)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
- fprintf(stream, "%*sFree Blocks (offset, size):\n", indent, "");
-
+ HDfprintf(stream, "%*sFree Blocks (offset, size):\n", indent, "");
for(free_block = 0, freelist = h->freelist; freelist; freelist = freelist->next, free_block++) {
char temp_str[32];
- sprintf(temp_str,"Block #%d:",free_block);
+ HDsnprintf(temp_str, sizeof(temp_str), "Block #%d:", free_block);
HDfprintf(stream, "%*s%-*s %8Zu, %8Zu\n", indent+3, "", MAX(0,fwidth-9),
temp_str,
freelist->offset, freelist->size);
if((freelist->offset + freelist->size) > h->dblk_size)
- fprintf(stream, "***THAT FREE BLOCK IS OUT OF BOUNDS!\n");
+ HDfprintf(stream, "***THAT FREE BLOCK IS OUT OF BOUNDS!\n");
else {
- for(i = overlap = 0; i < (int)(freelist->size); i++) {
+ int overlap = 0;
+ size_t i;
+
+ for(i = 0; i < freelist->size; i++) {
if(marker[freelist->offset + i])
overlap++;
marker[freelist->offset + i] = 1;
} /* end for */
if(overlap)
- fprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n");
+ HDfprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n");
else
amount_free += freelist->size;
} /* end for */
} /* end for */
if(h->dblk_size)
- fprintf(stream, "%*s%-*s %.2f%%\n", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s %.2f%%\n", indent, "", fwidth,
"Percent of heap used:",
- (100.0 * (double)(h->dblk_size - amount_free) / (double)h->dblk_size));
+ ((double)100.0f * (double)(h->dblk_size - amount_free) / (double)h->dblk_size));
/*
* Print the data in a VMS-style octal dump.
diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c
index 69cc157..9d1fe48 100644
--- a/src/H5Lexternal.c
+++ b/src/H5Lexternal.c
@@ -208,6 +208,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group,
char *parent_group_name = NULL;/* Temporary pointer to group name */
char local_group_name[H5L_EXT_TRAVERSE_BUF_SIZE]; /* Local buffer to hold group name */
char *temp_file_name = NULL; /* Temporary pointer to file name */
+ size_t temp_file_name_len; /* Length of temporary file name */
char *actual_file_name = NULL; /* Parent file's actual name */
H5P_genplist_t *fa_plist; /* File access property list pointer */
H5F_close_degree_t fc_degree = H5F_CLOSE_WEAK; /* File close degree for target file */
@@ -312,6 +313,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group,
/* Copy the file name to use */
if(NULL == (temp_file_name = H5MM_strdup(file_name)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ temp_file_name_len = HDstrlen(temp_file_name);
/* target file_name is an absolute pathname: see RM for detailed description */
if(H5_CHECK_ABSOLUTE(file_name) || H5_CHECK_ABS_PATH(file_name)) {
@@ -329,7 +331,8 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group,
ptr++;
/* Copy into the temp. file name */
- HDstrncpy(temp_file_name, ptr, HDstrlen(ptr) + 1);
+ HDstrncpy(temp_file_name, ptr, temp_file_name_len);
+ temp_file_name[temp_file_name_len - 1] = '\0';
} /* end if */
} /* end if */
else if(H5_CHECK_ABS_DRIVE(file_name)) {
@@ -339,7 +342,8 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group,
H5E_clear_stack(NULL);
/* strip "<drive-letter>:" */
- HDstrncpy(temp_file_name, &file_name[2], (HDstrlen(file_name) - 2) + 1);
+ HDstrncpy(temp_file_name, &file_name[2], temp_file_name_len);
+ temp_file_name[temp_file_name_len - 1] = '\0';
} /* end if */
} /* end if */
@@ -579,9 +583,9 @@ H5Lcreate_external(const char *file_name, const char *obj_name,
/* Encode the external link information */
p = (uint8_t *)ext_link_buf;
*p++ = (H5L_EXT_VERSION << 4) | H5L_EXT_FLAGS_ALL; /* External link version & flags */
- HDstrncpy((char *)p, file_name, file_name_len); /* Name of file containing external link's object */
+ HDstrncpy((char *)p, file_name, buf_size - 1); /* Name of file containing external link's object */
p += file_name_len;
- HDstrncpy((char *)p, norm_obj_name, norm_obj_name_len); /* External link's object */
+ HDstrncpy((char *)p, norm_obj_name, buf_size - (file_name_len + 1)); /* External link's object */
/* Create an external link */
if(H5L_create_ud(&link_loc, link_name, ext_link_buf, buf_size, H5L_TYPE_EXTERNAL, lcpl_id, lapl_id, H5AC_dxpl_id) < 0)
diff --git a/src/H5Oattr.c b/src/H5Oattr.c
index b8e6b32..2269bd3 100644
--- a/src/H5Oattr.c
+++ b/src/H5Oattr.c
@@ -793,7 +793,7 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in
{
const H5A_t *mesg = (const H5A_t *)_mesg;
const char *s; /* Temporary string pointer */
- char buf[256]; /* Temporary string buffer */
+ char buf[128]; /* Temporary string buffer */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -804,7 +804,7 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in
HDassert(indent >= 0);
HDassert(fwidth >= 0);
- fprintf(stream, "%*s%-*s \"%s\"\n", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s \"%s\"\n", indent, "", fwidth,
"Name:",
mesg->shared->name);
switch(mesg->shared->encoding) {
@@ -830,17 +830,17 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in
case H5T_CSET_RESERVED_13:
case H5T_CSET_RESERVED_14:
case H5T_CSET_RESERVED_15:
- sprintf(buf, "H5T_CSET_RESERVED_%d", (int)(mesg->shared->encoding));
+ HDsnprintf(buf, sizeof(buf), "H5T_CSET_RESERVED_%d", (int)(mesg->shared->encoding));
s = buf;
break;
case H5T_CSET_ERROR:
default:
- sprintf(buf, "Unknown character set: %d", (int)(mesg->shared->encoding));
+ HDsnprintf(buf, sizeof(buf), "Unknown character set: %d", (int)(mesg->shared->encoding));
s = buf;
break;
} /* end switch */
- fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
"Character Set of Name:",
s);
HDfprintf(stream, "%*s%-*s %t\n", indent, "", fwidth,
@@ -856,18 +856,18 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in
"Creation Index:",
(unsigned)mesg->shared->crt_idx);
- fprintf(stream, "%*sDatatype...\n", indent, "");
- fprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX(0,fwidth-3),
+ HDfprintf(stream, "%*sDatatype...\n", indent, "");
+ HDfprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MAX(0,fwidth - 3),
"Encoded Size:",
(unsigned long)(mesg->shared->dt_size));
if((H5O_MSG_DTYPE->debug)(f, dxpl_id, mesg->shared->dt, stream, indent + 3, MAX(0, fwidth - 3)) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to display datatype message info")
- fprintf(stream, "%*sDataspace...\n", indent, "");
- fprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX(0, fwidth - 3),
+ HDfprintf(stream, "%*sDataspace...\n", indent, "");
+ HDfprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MAX(0, fwidth - 3),
"Encoded Size:",
(unsigned long)(mesg->shared->ds_size));
- if(H5S_debug(f, dxpl_id, mesg->shared->ds, stream, indent+3, MAX(0, fwidth - 3)) < 0)
+ if(H5S_debug(f, dxpl_id, mesg->shared->ds, stream, indent + 3, MAX(0, fwidth - 3)) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to display dataspace message info")
done:
diff --git a/src/H5Oefl.c b/src/H5Oefl.c
index 1297780..bbc7e92 100644
--- a/src/H5Oefl.c
+++ b/src/H5Oefl.c
@@ -545,7 +545,6 @@ H5O_efl_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * s
int indent, int fwidth)
{
const H5O_efl_t *mesg = (const H5O_efl_t *) _mesg;
- char buf[64];
size_t u;
FUNC_ENTER_NOAPI_NOINIT_NOERR
@@ -565,8 +564,10 @@ H5O_efl_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * s
mesg->nused, mesg->nalloc);
for(u = 0; u < mesg->nused; u++) {
- sprintf (buf, "File %u", (unsigned)u);
- HDfprintf (stream, "%*s%s:\n", indent, "", buf);
+ char buf[64];
+
+ HDsnprintf(buf, sizeof(buf), "File %u", (unsigned)u);
+ HDfprintf(stream, "%*s%s:\n", indent, "", buf);
HDfprintf(stream, "%*s%-*s \"%s\"\n", indent+3, "", MAX (fwidth-3, 0),
"Name:",
@@ -576,11 +577,11 @@ H5O_efl_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * s
"Name offset:",
(unsigned long)(mesg->slot[u].name_offset));
- HDfprintf (stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0),
+ HDfprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0),
"Offset of data in file:",
(unsigned long)(mesg->slot[u].offset));
- HDfprintf (stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0),
+ HDfprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0),
"Bytes reserved for data:",
(unsigned long)(mesg->slot[u].size));
} /* end for */
diff --git a/src/H5system.c b/src/H5system.c
index 4280066..437a004 100644
--- a/src/H5system.c
+++ b/src/H5system.c
@@ -200,20 +200,28 @@ HDfprintf(FILE *stream, const char *fmt, ...)
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);
+ else if(sizeof(hsize_t) == sizeof(long)) {
+ HDstrncpy(modifier, "l", sizeof(modifier));
+ modifier[sizeof(modifier) - 1] = '\0';
+ } /* end if */
+ else {
+ HDstrncpy(modifier, H5_PRINTF_LL_WIDTH, sizeof(modifier));
+ modifier[sizeof(modifier) - 1] = '\0';
+ } /* end else */
break;
case 'Z':
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);
+ else if(sizeof(size_t) == sizeof(long)) {
+ HDstrncpy(modifier, "l", sizeof(modifier));
+ modifier[sizeof(modifier) - 1] = '\0';
+ } /* end if */
+ else {
+ HDstrncpy(modifier, H5_PRINTF_LL_WIDTH, sizeof(modifier));
+ modifier[sizeof(modifier) - 1] = '\0';
+ } /* end else */
break;
default: