VPP-229: fix NPE in JNI array handling

Change-Id: Ieb5182a7a3612e09bd2b28eb6a4abbdb4d29d34b
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
This commit is contained in:
Marek Gradzki
2016-08-01 07:59:06 +02:00
committed by Keith Burns
parent 7b75d211ae
commit 8e5458caea

View File

@ -107,7 +107,7 @@ u64_struct_setter_template = Template("""
mp->${c_name} = clib_host_to_net_u64(${java_name});""") mp->${c_name} = clib_host_to_net_u64(${java_name});""")
u8_array_struct_setter_template = Template(""" u8_array_struct_setter_template = Template("""
{ if (${java_name}) {
jsize cnt = (*env)->GetArrayLength (env, ${java_name}); jsize cnt = (*env)->GetArrayLength (env, ${java_name});
size_t max_size = ${field_length}; size_t max_size = ${field_length};
if (max_size != 0 && cnt > max_size) cnt = max_size; if (max_size != 0 && cnt > max_size) cnt = max_size;
@ -117,7 +117,7 @@ u8_array_struct_setter_template = Template("""
u16_array_struct_setter_template = Template(""" u16_array_struct_setter_template = Template("""
jshort * ${java_name}ArrayElements = (*env)->GetShortArrayElements(env, ${java_name}, NULL); jshort * ${java_name}ArrayElements = (*env)->GetShortArrayElements(env, ${java_name}, NULL);
{ if (${java_name}) {
size_t _i; size_t _i;
jsize cnt = (*env)->GetArrayLength (env, ${java_name}); jsize cnt = (*env)->GetArrayLength (env, ${java_name});
size_t max_size = ${field_length}; size_t max_size = ${field_length};
@ -131,7 +131,7 @@ u16_array_struct_setter_template = Template("""
u32_array_struct_setter_template = Template(""" u32_array_struct_setter_template = Template("""
jint * ${java_name}ArrayElements = (*env)->GetIntArrayElements(env, ${java_name}, NULL); jint * ${java_name}ArrayElements = (*env)->GetIntArrayElements(env, ${java_name}, NULL);
{ if (${java_name}) {
size_t _i; size_t _i;
jsize cnt = (*env)->GetArrayLength (env, ${java_name}); jsize cnt = (*env)->GetArrayLength (env, ${java_name});
size_t max_size = ${field_length}; size_t max_size = ${field_length};
@ -145,7 +145,7 @@ u32_array_struct_setter_template = Template("""
u64_array_struct_setter_template = Template(""" u64_array_struct_setter_template = Template("""
jlong * ${java_name}ArrayElements = (*env)->GetLongArrayElements(env, ${java_name}, NULL); jlong * ${java_name}ArrayElements = (*env)->GetLongArrayElements(env, ${java_name}, NULL);
{ if (${java_name}) {
size_t _i; size_t _i;
jsize cnt = (*env)->GetArrayLength (env, ${java_name}); jsize cnt = (*env)->GetArrayLength (env, ${java_name});
size_t max_size = ${field_length}; size_t max_size = ${field_length};