summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/h5tools_str.c')
-rw-r--r--tools/lib/h5tools_str.c14
1 files changed, 8 insertions, 6 deletions
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 {