diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2023-05-27 16:49:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-27 16:49:37 (GMT) |
commit | 40324e0c31eef2cfcf0289079c58f81717d65184 (patch) | |
tree | ac1cc1d5651e223e9d16b05ffd94e3d0455be695 /java/src/jni/h5dImp.c | |
parent | 79bb60c3f6f67411e5d70b84743fc9f6b6143cbc (diff) | |
download | hdf5-40324e0c31eef2cfcf0289079c58f81717d65184.zip hdf5-40324e0c31eef2cfcf0289079c58f81717d65184.tar.gz hdf5-40324e0c31eef2cfcf0289079c58f81717d65184.tar.bz2 |
Cleans up Java JNI warnings and add java to -Werror checks (#2383)
Diffstat (limited to 'java/src/jni/h5dImp.c')
-rw-r--r-- | java/src/jni/h5dImp.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c index efddb96..de7fb21 100644 --- a/java/src/jni/h5dImp.c +++ b/java/src/jni/h5dImp.c @@ -1134,7 +1134,6 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { - jboolean readBufIsCopy; jbyte *readBuf = NULL; size_t typeSize; H5T_class_t type_class; @@ -1195,7 +1194,6 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { - jboolean writeBufIsCopy; jbyte *writeBuf = NULL; size_t typeSize; H5T_class_t type_class; @@ -1680,21 +1678,24 @@ H5DwriteVL_asstr(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_si continue; } - /* - * length = ENVPTR->GetStringUTFLength(ENVONLY, jstr); - * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - */ - PIN_JAVA_STRING(ENVONLY, jstr, utf8, NULL, "H5DwriteVL_asstr: failed to pin string buffer"); /* - * TODO: If the string isn't a copy, we should probably make - * one before destroying it with h5str_convert. + * Make a copy of the string since h5str_convert uses strtok. */ + char *utf8_copy = NULL; - if (!h5str_convert(ENVONLY, (char **)&utf8, did, tid, &(((char *)writeBuf)[i * typeSize]), 0)) + jsize length = ENVPTR->GetStringUTFLength(ENVONLY, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (utf8_copy = HDstrndup(utf8, (size_t)length))) + H5_LIBRARY_ERROR(ENVONLY); + + if (!h5str_convert(ENVONLY, &utf8_copy, did, tid, &(((char *)writeBuf)[i * typeSize]), 0)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + HDfree(utf8_copy); + UNPIN_JAVA_STRING(ENVONLY, jstr, utf8); utf8 = NULL; |