From c5e00232ffb9f13177fec21c1b425418dc2707f1 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 4 May 2011 15:28:09 -0500 Subject: [svn-r20725] Add overlooked changes from part of coverity fix Tested: local linux --- tools/lib/h5tools.c | 9 +++++++-- tools/lib/h5tools_str.c | 14 ++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 3d96bed..bb951a0 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -311,7 +311,7 @@ h5tools_init(void) if (!h5tools_init_g) { /* register the error class */ - sprintf(lib_str, "%d.%d.%d",H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); + HDsnprintf(lib_str, sizeof(lib_str), "%d.%d.%d",H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); H5TOOLS_INIT_ERROR() @@ -3191,7 +3191,12 @@ h5tools_print_datatype(h5tools_str_t *buffer, const h5tool_format_t *info, case H5T_OPAQUE: h5tools_str_append(buffer, "\n"); h5tools_str_append(buffer, "H5T_OPAQUE;\n"); - h5tools_str_append(buffer, "OPAQUE_TAG \"%s\";\n", H5Tget_tag(type)); + { + char *ttag = H5Tget_tag(type); + h5tools_str_append(buffer, "OPAQUE_TAG \"%s\";\n", ttag); + if (ttag) + HDfree(ttag); + } break; case H5T_COMPOUND: diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index ed13ac4..19d251b 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -281,12 +281,14 @@ h5tools_str_fmt(h5tools_str_t *str/*in,out*/, size_t start, const char *fmt) * don't bother because we don't need a temporary copy. */ if (strchr(fmt, '%')) { - if (str->len - start + 1 > sizeof(_temp)) { - temp = malloc(str->len - start + 1); + size_t n = sizeof(_temp); + if (str->len - start + 1 > n) { + n = str->len - start + 1; + temp = malloc(n); assert(temp); } - strcpy(temp, str->s + start); + HDstrncpy(temp, str->s + start, n); } /* Reset the output string and append a formatted version */ @@ -669,8 +671,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai /* Build default formats for long long types */ if (!fmt_llong[0]) { - sprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH); - sprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH); + snprintf(fmt_llong, sizeof(fmt_llong), "%%%sd", H5_PRINTF_LL_WIDTH); + snprintf(fmt_ullong, sizeof(fmt_ullong), "%%%su", H5_PRINTF_LL_WIDTH); } /* Append value depending on data type */ @@ -1252,7 +1254,7 @@ h5tools_escape(char *s/*in,out*/, size_t size) break; default: if (!isprint(s[i])) { - sprintf(octal, "\\%03o", (unsigned char) s[i]); + snprintf(octal, sizeof(octal), "\\%03o", (unsigned char) s[i]); escape = octal; } else { -- cgit v0.12