summaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/jni/h5aImp.c115
-rw-r--r--java/src/jni/h5dImp.c114
-rw-r--r--java/src/jni/h5rImp.c2
-rw-r--r--java/src/jni/h5util.c23
4 files changed, 146 insertions, 108 deletions
diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c
index eeed806..0bc17d1 100644
--- a/java/src/jni/h5aImp.c
+++ b/java/src/jni/h5aImp.c
@@ -1067,10 +1067,9 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
H5T_class_t type_class;
hsize_t dims[H5S_MAX_RANK];
hid_t sid = H5I_INVALID_HID;
- jsize n;
+ jsize n = 0;
htri_t vl_data_class;
- herr_t status = FAIL;
- jboolean readBufIsCopy;
+ herr_t status = FAIL;
jbyteArray *readBuf = NULL;
UNUSED(clss);
@@ -1104,7 +1103,6 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
jobject *jList = NULL;
size_t i, j, x;
- char *cp_vp = NULL;
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -1123,7 +1121,7 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
H5_LIBRARY_ERROR(ENVONLY);
/* Cache class types */
- jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean");
+ /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
@@ -1131,8 +1129,10 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
+ /*
jmethodID boolValueMid =
ENVPTR->GetStaticMethodID(ENVONLY, cBool, "valueOf", "(Z)Ljava/lang/Boolean;");
+ */
jmethodID byteValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cByte, "valueOf", "(B)Ljava/lang/Byte;");
jmethodID shortValueMid =
ENVPTR->GetStaticMethodID(ENVONLY, cShort, "valueOf", "(S)Ljava/lang/Short;");
@@ -1149,21 +1149,28 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
/* Convert each element to a list */
for (i = 0; i < (size_t)n; i++) {
+ hvl_t vl_elem;
+
// The list we're going to return:
if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- cp_vp = (char *)rawBuf + i * typeSize;
/* Get the number of sequence elements */
- jsize nelmts = ((hvl_t *)cp_vp)->len;
+ HDmemcpy(&vl_elem, (char *)rawBuf + i * typeSize, sizeof(hvl_t));
+
+ jsize nelmts = (jsize)vl_elem.len;
+ if (vl_elem.len != (size_t)nelmts)
+ H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL: overflow of number of VL elements");
+ if (nelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: number of VL elements < 0");
jobject jobj = NULL;
- for (j = 0; j < nelmts; j++) {
+ for (j = 0; j < (size_t)nelmts; j++) {
switch (vlClass) {
/* case H5T_BOOL: {
jboolean boolValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&boolValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j*vlSize+x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&boolValue)[x] = ((char *)vl_elem.p)[j*vlSize+x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue);
@@ -1174,8 +1181,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
switch (vlSize) {
case sizeof(jbyte): {
jbyte byteValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&byteValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&byteValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj =
@@ -1185,8 +1192,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
}
case sizeof(jshort): {
jshort shortValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&shortValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&shortValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid,
@@ -1196,8 +1203,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
}
case sizeof(jint): {
jint intValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&intValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&intValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue);
@@ -1206,8 +1213,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
}
case sizeof(jlong): {
jlong longValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&longValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&longValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj =
@@ -1222,8 +1229,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
switch (vlSize) {
case sizeof(jfloat): {
jfloat floatValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&floatValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&floatValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
@@ -1233,8 +1240,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
}
case sizeof(jdouble): {
jdouble doubleValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&doubleValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&doubleValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
@@ -1248,14 +1255,19 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
case H5T_REFERENCE: {
jboolean bb;
jbyte *barray = NULL;
- if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, vlSize)))
+
+ jsize byteArraySize = (jsize)vlSize;
+ if (vlSize != (size_t)byteArraySize)
+ H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL: overflow of byteArraySize");
+
+ if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb,
"readVL reference: byte array not pinned");
- for (x = 0; x < (int)vlSize; x++) {
- barray[x] = ((jbyte *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ barray[x] = ((jbyte *)vl_elem.p)[j * vlSize + x];
}
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
@@ -1340,7 +1352,6 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
jobject *jList = NULL;
size_t i, j, x;
- char *cp_vp = NULL;
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -1356,7 +1367,7 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL: failed to allocate raw VL write buffer");
/* Cache class types */
- jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean");
+ /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
@@ -1364,7 +1375,7 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
- jmethodID boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z");
+ /* jmethodID boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z"); */
jmethodID byteValueMid = ENVPTR->GetMethodID(ENVONLY, cByte, "byteValue", "()B");
jmethodID shortValueMid = ENVPTR->GetMethodID(ENVONLY, cShort, "shortValue", "()S");
jmethodID intValueMid = ENVPTR->GetMethodID(ENVONLY, cInt, "intValue", "()I");
@@ -1374,6 +1385,8 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
/* Convert each list to a vlen element */
for (i = 0; i < (size_t)n; i++) {
+ hvl_t vl_elem;
+
if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
@@ -1387,22 +1400,25 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray);
jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
- cp_vp = (char *)rawBuf + i * typeSize;
- ((hvl_t *)cp_vp)->len = jnelmts;
+ if (jnelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: number of VL elements < 0");
- if (NULL == (((hvl_t *)cp_vp)->p = HDmalloc(jnelmts * vlSize)))
+ HDmemcpy(&vl_elem, (char *)rawBuf + i * typeSize, sizeof(hvl_t));
+ vl_elem.len = (size_t)jnelmts;
+
+ if (NULL == (vl_elem.p = HDmalloc((size_t)jnelmts * vlSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL: failed to allocate vlen ptr buffer");
jobject jobj = NULL;
- for (j = 0; j < (int)jnelmts; j++) {
+ for (j = 0; j < (size_t)jnelmts; j++) {
if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)array, (jsize)j)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
switch (vlClass) {
/* case H5T_BOOL: {
jboolean boolValue = ENVPTR->CallBooleanMethod(ENVONLY, jobj, boolValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&boolValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&boolValue)[x];
}
break;
} */
@@ -1410,29 +1426,29 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
switch (vlSize) {
case sizeof(jbyte): {
jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&byteValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&byteValue)[x];
}
break;
}
case sizeof(jshort): {
jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&shortValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&shortValue)[x];
}
break;
}
case sizeof(jint): {
jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&intValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&intValue)[x];
}
break;
}
case sizeof(jlong): {
jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&longValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&longValue)[x];
}
break;
}
@@ -1443,15 +1459,15 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
switch (vlSize) {
case sizeof(jfloat): {
jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&floatValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&floatValue)[x];
}
break;
}
case sizeof(jdouble): {
jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&doubleValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&doubleValue)[x];
}
break;
}
@@ -1460,8 +1476,8 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
}
case H5T_REFERENCE: {
jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)barray)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)barray)[x];
}
ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0);
break;
@@ -1472,6 +1488,9 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
}
ENVPTR->DeleteLocalRef(ENVONLY, jobj);
}
+
+ HDmemcpy((char *)rawBuf + i * typeSize, &vl_elem, sizeof(hvl_t));
+
ENVPTR->DeleteLocalRef(ENVONLY, jList);
} /* end for (i = 0; i < n; i++) */
diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c
index 4b32af3..c7d7c5d 100644
--- a/java/src/jni/h5dImp.c
+++ b/java/src/jni/h5dImp.c
@@ -1078,8 +1078,7 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
H5T_class_t type_class;
jsize n;
htri_t vl_data_class;
- herr_t status = FAIL;
- jboolean readBufIsCopy;
+ herr_t status = FAIL;
jbyteArray *readBuf = NULL;
UNUSED(clss);
@@ -1107,7 +1106,6 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
jobject *jList = NULL;
size_t i, j, x;
- char *cp_vp = NULL;
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -1127,7 +1125,7 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
H5_LIBRARY_ERROR(ENVONLY);
/* Cache class types */
- jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean");
+ /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
@@ -1135,8 +1133,10 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
+ /*
jmethodID boolValueMid =
ENVPTR->GetStaticMethodID(ENVONLY, cBool, "valueOf", "(Z)Ljava/lang/Boolean;");
+ */
jmethodID byteValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cByte, "valueOf", "(B)Ljava/lang/Byte;");
jmethodID shortValueMid =
ENVPTR->GetStaticMethodID(ENVONLY, cShort, "valueOf", "(S)Ljava/lang/Short;");
@@ -1153,21 +1153,28 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
/* Convert each element to a list */
for (i = 0; i < (size_t)n; i++) {
+ hvl_t vl_elem;
+
// The list we're going to return:
if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- cp_vp = (char *)rawBuf + i * typeSize;
/* Get the number of sequence elements */
- jsize nelmts = ((hvl_t *)cp_vp)->len;
+ HDmemcpy(&vl_elem, (char *)rawBuf + i * typeSize, sizeof(hvl_t));
+
+ jsize nelmts = (jsize)vl_elem.len;
+ if (vl_elem.len != (size_t)nelmts)
+ H5_JNI_FATAL_ERROR(ENVONLY, "H5DreadVL: overflow of number of VL elements");
+ if (nelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: number of VL elements < 0");
jobject jobj = NULL;
- for (j = 0; j < nelmts; j++) {
+ for (j = 0; j < (size_t)nelmts; j++) {
switch (vlClass) {
/*case H5T_BOOL: {
jboolean boolValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&boolValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j*vlSize+x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&boolValue)[x] = ((char *)vl_elem.p)[j*vlSize+x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue);
@@ -1178,8 +1185,8 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
switch (vlSize) {
case sizeof(jbyte): {
jbyte byteValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&byteValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&byteValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj =
@@ -1189,8 +1196,8 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
}
case sizeof(jshort): {
jshort shortValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&shortValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&shortValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid,
@@ -1200,8 +1207,8 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
}
case sizeof(jint): {
jint intValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&intValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&intValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue);
@@ -1210,8 +1217,8 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
}
case sizeof(jlong): {
jlong longValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&longValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&longValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj =
@@ -1226,8 +1233,8 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
switch (vlSize) {
case sizeof(jfloat): {
jfloat floatValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&floatValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&floatValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
@@ -1237,8 +1244,8 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
}
case sizeof(jdouble): {
jdouble doubleValue;
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)&doubleValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)&doubleValue)[x] = ((char *)vl_elem.p)[j * vlSize + x];
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
@@ -1252,14 +1259,19 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
case H5T_REFERENCE: {
jboolean bb;
jbyte *barray = NULL;
- if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, vlSize)))
+
+ jsize byteArraySize = (jsize)vlSize;
+ if (vlSize != (size_t)byteArraySize)
+ H5_JNI_FATAL_ERROR(ENVONLY, "H5DreadVL: overflow of byteArraySize");
+
+ if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb,
"readVL reference: byte array not pinned");
- for (x = 0; x < (int)vlSize; x++) {
- barray[x] = ((jbyte *)((hvl_t *)cp_vp)->p)[j * vlSize + x];
+ for (x = 0; x < vlSize; x++) {
+ barray[x] = ((jbyte *)vl_elem.p)[j * vlSize + x];
}
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
@@ -1337,7 +1349,6 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
jobject *jList = NULL;
size_t i, j, x;
- char *cp_vp = NULL;
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -1353,7 +1364,7 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DwriteVL: failed to allocate raw VL write buffer");
/* Cache class types */
- jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean");
+ /* jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); */
jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
@@ -1361,7 +1372,7 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
- jmethodID boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z");
+ /* jmethodID boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z"); */
jmethodID byteValueMid = ENVPTR->GetMethodID(ENVONLY, cByte, "byteValue", "()B");
jmethodID shortValueMid = ENVPTR->GetMethodID(ENVONLY, cShort, "shortValue", "()S");
jmethodID intValueMid = ENVPTR->GetMethodID(ENVONLY, cInt, "intValue", "()I");
@@ -1371,6 +1382,8 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
/* Convert each list to a vlen element */
for (i = 0; i < (size_t)n; i++) {
+ hvl_t vl_elem;
+
if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
@@ -1384,21 +1397,25 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray);
jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
- cp_vp = (char *)rawBuf + i * typeSize;
- ((hvl_t *)cp_vp)->len = jnelmts;
+ if (jnelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: number of VL elements < 0");
+
+ HDmemcpy(&vl_elem, (char *)rawBuf + i * typeSize, sizeof(hvl_t));
+ vl_elem.len = (size_t)jnelmts;
- if (NULL == (((hvl_t *)cp_vp)->p = HDmalloc(jnelmts * vlSize)))
+ if (NULL == (vl_elem.p = HDmalloc((size_t)jnelmts * vlSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DwriteVL: failed to allocate vlen ptr buffer");
+
jobject jobj = NULL;
- for (j = 0; j < (int)jnelmts; j++) {
+ for (j = 0; j < (size_t)jnelmts; j++) {
if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)array, (jsize)j)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
switch (vlClass) {
/* case H5T_BOOL: {
jboolean boolValue = ENVPTR->CallBooleanMethod(ENVONLY, jobj, boolValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&boolValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&boolValue)[x];
}
break;
} */
@@ -1406,29 +1423,29 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
switch (vlSize) {
case sizeof(jbyte): {
jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&byteValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&byteValue)[x];
}
break;
}
case sizeof(jshort): {
jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&shortValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&shortValue)[x];
}
break;
}
case sizeof(jint): {
jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&intValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&intValue)[x];
}
break;
}
case sizeof(jlong): {
jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&longValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&longValue)[x];
}
break;
}
@@ -1439,15 +1456,15 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
switch (vlSize) {
case sizeof(jfloat): {
jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&floatValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&floatValue)[x];
}
break;
}
case sizeof(jdouble): {
jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&doubleValue)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)&doubleValue)[x];
}
break;
}
@@ -1456,8 +1473,8 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
}
case H5T_REFERENCE: {
jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0);
- for (x = 0; x < (int)vlSize; x++) {
- ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)barray)[x];
+ for (x = 0; x < vlSize; x++) {
+ ((char *)vl_elem.p)[j * vlSize + x] = ((char *)barray)[x];
}
ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0);
break;
@@ -1468,6 +1485,9 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
}
ENVPTR->DeleteLocalRef(ENVONLY, jobj);
}
+
+ HDmemcpy((char *)rawBuf + i * typeSize, &vl_elem, sizeof(hvl_t));
+
ENVPTR->DeleteLocalRef(ENVONLY, jList);
} /* end for (i = 0; i < n; i++) */
diff --git a/java/src/jni/h5rImp.c b/java/src/jni/h5rImp.c
index 54f4a01..763be05 100644
--- a/java/src/jni/h5rImp.c
+++ b/java/src/jni/h5rImp.c
@@ -312,7 +312,7 @@ Java_hdf_hdf5lib_H5_H5Rget_1name_1string(JNIEnv *env, jclass clss, jlong loc_id,
jbyteArray ref)
{
jboolean isCopy;
- jstring str;
+ jstring str = NULL;
jsize refBufLen;
jbyte *refBuf = NULL;
char *aName = NULL;
diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c
index 1e69428..5344d18 100644
--- a/java/src/jni/h5util.c
+++ b/java/src/jni/h5util.c
@@ -650,10 +650,8 @@ done:
int
h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t region_obj, void *ref_buf)
{
- hid_t region = H5I_INVALID_HID;
- char ref_name[1024];
-
- int ret_value = FAIL;
+ char ref_name[1024];
+ int ret_value = FAIL;
if ((H5Rget_name(region_obj, H5R_DATASET_REGION, ref_buf, (char *)ref_name, 1024)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
@@ -661,8 +659,8 @@ h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t region_obj, void *re
H5_ASSERTION_ERROR(ENVONLY, "Unable to append string.");
ret_value = SUCCEED;
-done:
+done:
return ret_value;
} /* h5str_sprint_reference */
@@ -2132,14 +2130,15 @@ h5str_render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hs
}
for (block_index = 0; block_index < block_nelmts; block_index++) {
- mem = ((unsigned char *)_mem) + block_index * size;
+ hvl_t vl_elem;
+
+ HDmemcpy(&vl_elem, ((unsigned char *)_mem) + block_index * size, sizeof(hvl_t));
/* Get the number of sequence elements */
- nelmts = ((hvl_t *)mem)->len;
+ nelmts = vl_elem.len;
/* dump the array element */
- if (h5str_render_bin_output(stream, container, memb, ((char *)(((hvl_t *)mem)->p)), nelmts) <
- 0) {
+ if (h5str_render_bin_output(stream, container, memb, ((char *)(vl_elem.p)), nelmts) < 0) {
ret_value = FAIL;
break;
}
@@ -2563,8 +2562,8 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
int carry; /* counter carry value */
/* Print info */
- hsize_t p_nelmts; /* total selected elmts */
- size_t p_type_nbytes; /* size of memory type */
+ hssize_t p_nelmts; /* total selected elmts */
+ size_t p_type_nbytes; /* size of memory type */
/* Stripmine info */
unsigned char *sm_buf = NULL; /* buffer for raw data */
@@ -2758,7 +2757,7 @@ h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr_id, int binary_order
int ndims; /* rank of dataspace */
unsigned i; /* counters */
hsize_t total_size[H5S_MAX_RANK]; /* total size of dataset*/
- hsize_t p_nelmts; /* total selected elmts */
+ hssize_t p_nelmts; /* total selected elmts */
unsigned char *sm_buf = NULL; /* buffer for raw data */
hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */