summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorSean McBride <sean@rogue-research.com>2024-02-13 14:22:17 (GMT)
committerLarry Knox <lrknox@hdfgroup.org>2024-02-14 22:11:03 (GMT)
commit4aeaa9c2d47897c37409ee724cf83eae04617ab4 (patch)
treedc5baf544b8f0db38eb4d69dafe2cffefecae3e3 /java
parentb8574044c4259fb6959c97496fc28734d1ec1e55 (diff)
downloadhdf5-4aeaa9c2d47897c37409ee724cf83eae04617ab4.zip
hdf5-4aeaa9c2d47897c37409ee724cf83eae04617ab4.tar.gz
hdf5-4aeaa9c2d47897c37409ee724cf83eae04617ab4.tar.bz2
Issue #1824: Replaced most remaining sprintf with safer snprint (#4003)
Diffstat (limited to 'java')
-rw-r--r--java/src/jni/h5util.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c
index 76c726a..bf798b8 100644
--- a/java/src/jni/h5util.c
+++ b/java/src/jni/h5util.c
@@ -1192,7 +1192,8 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i
* object.
*/
- if (NULL == (this_str = (char *)malloc(64)))
+ const size_t size = 64;
+ if (NULL == (this_str = (char *)malloc(size)))
H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer");
if ((obj = H5Rdereference2(container, H5P_DEFAULT, H5R_OBJECT, cptr)) < 0)
@@ -1206,25 +1207,25 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i
switch (oi.type) {
case H5O_TYPE_GROUP:
- if (sprintf(this_str, "%s %s", H5_TOOLS_GROUP, obj_tok_str) < 0)
- H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure");
+ if (snprintf(this_str, size, "%s %s", H5_TOOLS_GROUP, obj_tok_str) < 0)
+ H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: snprintf failure");
break;
case H5O_TYPE_DATASET:
- if (sprintf(this_str, "%s %s", H5_TOOLS_DATASET, obj_tok_str) < 0)
- H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure");
+ if (snprintf(this_str, size, "%s %s", H5_TOOLS_DATASET, obj_tok_str) < 0)
+ H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: snprintf failure");
break;
case H5O_TYPE_NAMED_DATATYPE:
- if (sprintf(this_str, "%s %s", H5_TOOLS_DATATYPE, obj_tok_str) < 0)
- H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure");
+ if (snprintf(this_str, size, "%s %s", H5_TOOLS_DATATYPE, obj_tok_str) < 0)
+ H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: snprintf failure");
break;
case H5O_TYPE_UNKNOWN:
case H5O_TYPE_NTYPES:
default:
- if (sprintf(this_str, "%u-%s", (unsigned)oi.type, obj_tok_str) < 0)
- H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure");
+ if (snprintf(this_str, size, "%u-%s", (unsigned)oi.type, obj_tok_str) < 0)
+ H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: snprintf failure");
break;
}