@@ -536,13 +536,14 @@ void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBO
536
536
jboolean * jpTemp ;
537
537
CK_ULONG i ;
538
538
539
- * ckpLength = jArray == NULL ? 0L : (* env )-> GetArrayLength (env , jArray );
540
- if (* ckpLength == 0L ) {
539
+ if (jArray == NULL ) {
541
540
* ckpArray = NULL_PTR ;
541
+ * ckpLength = 0UL ;
542
542
return ;
543
543
}
544
+ * ckpLength = (* env )-> GetArrayLength (env , jArray );
544
545
jpTemp = (jboolean * ) calloc (* ckpLength , sizeof (jboolean ));
545
- if (jpTemp == NULL ) {
546
+ if (jpTemp == NULL && * ckpLength != 0UL ) {
546
547
p11ThrowOutOfMemoryError (env , 0 );
547
548
return ;
548
549
}
@@ -552,8 +553,8 @@ void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBO
552
553
return ;
553
554
}
554
555
555
- * ckpArray = (CK_BBOOL * ) calloc (* ckpLength , sizeof (CK_BBOOL ));
556
- if (* ckpArray == NULL ) {
556
+ * ckpArray = (CK_BBOOL * ) calloc (* ckpLength , sizeof (CK_BBOOL ));
557
+ if (* ckpArray == NULL && * ckpLength != 0UL ) {
557
558
free (jpTemp );
558
559
p11ThrowOutOfMemoryError (env , 0 );
559
560
return ;
@@ -577,13 +578,14 @@ void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *
577
578
jbyte * jpTemp ;
578
579
CK_ULONG i ;
579
580
580
- * ckpLength = jArray == NULL ? 0L : (* env )-> GetArrayLength (env , jArray );
581
- if (* ckpLength == 0L ) {
581
+ if (jArray == NULL ) {
582
582
* ckpArray = NULL_PTR ;
583
+ * ckpLength = 0UL ;
583
584
return ;
584
585
}
586
+ * ckpLength = (* env )-> GetArrayLength (env , jArray );
585
587
jpTemp = (jbyte * ) calloc (* ckpLength , sizeof (jbyte ));
586
- if (jpTemp == NULL ) {
588
+ if (jpTemp == NULL && * ckpLength != 0UL ) {
587
589
p11ThrowOutOfMemoryError (env , 0 );
588
590
return ;
589
591
}
@@ -597,8 +599,8 @@ void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *
597
599
if (sizeof (CK_BYTE ) == sizeof (jbyte )) {
598
600
* ckpArray = (CK_BYTE_PTR ) jpTemp ;
599
601
} else {
600
- * ckpArray = (CK_BYTE_PTR ) calloc (* ckpLength , sizeof (CK_BYTE ));
601
- if (* ckpArray == NULL ) {
602
+ * ckpArray = (CK_BYTE_PTR ) calloc (* ckpLength , sizeof (CK_BYTE ));
603
+ if (* ckpArray == NULL && * ckpLength != 0UL ) {
602
604
free (jpTemp );
603
605
p11ThrowOutOfMemoryError (env , 0 );
604
606
return ;
@@ -623,13 +625,14 @@ void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR
623
625
jlong * jTemp ;
624
626
CK_ULONG i ;
625
627
626
- * ckpLength = jArray == NULL ? 0L : (* env )-> GetArrayLength (env , jArray );
627
- if (* ckpLength == 0L ) {
628
+ if (jArray == NULL ) {
628
629
* ckpArray = NULL_PTR ;
630
+ * ckpLength = 0UL ;
629
631
return ;
630
632
}
633
+ * ckpLength = (* env )-> GetArrayLength (env , jArray );
631
634
jTemp = (jlong * ) calloc (* ckpLength , sizeof (jlong ));
632
- if (jTemp == NULL ) {
635
+ if (jTemp == NULL && * ckpLength != 0UL ) {
633
636
p11ThrowOutOfMemoryError (env , 0 );
634
637
return ;
635
638
}
@@ -640,7 +643,7 @@ void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR
640
643
}
641
644
642
645
* ckpArray = (CK_ULONG_PTR ) calloc (* ckpLength , sizeof (CK_ULONG ));
643
- if (* ckpArray == NULL ) {
646
+ if (* ckpArray == NULL && * ckpLength != 0UL ) {
644
647
free (jTemp );
645
648
p11ThrowOutOfMemoryError (env , 0 );
646
649
return ;
@@ -664,13 +667,14 @@ void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *
664
667
jchar * jpTemp ;
665
668
CK_ULONG i ;
666
669
667
- * ckpLength = jArray == NULL ? 0L : (* env )-> GetArrayLength (env , jArray );
668
- if (* ckpLength == 0L ) {
670
+ if (jArray == NULL ) {
669
671
* ckpArray = NULL_PTR ;
672
+ * ckpLength = 0UL ;
670
673
return ;
671
674
}
675
+ * ckpLength = (* env )-> GetArrayLength (env , jArray );
672
676
jpTemp = (jchar * ) calloc (* ckpLength , sizeof (jchar ));
673
- if (jpTemp == NULL ) {
677
+ if (jpTemp == NULL && * ckpLength != 0UL ) {
674
678
p11ThrowOutOfMemoryError (env , 0 );
675
679
return ;
676
680
}
@@ -680,8 +684,8 @@ void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *
680
684
return ;
681
685
}
682
686
683
- * ckpArray = (CK_CHAR_PTR ) calloc (* ckpLength , sizeof (CK_CHAR ));
684
- if (* ckpArray == NULL ) {
687
+ * ckpArray = (CK_CHAR_PTR ) calloc (* ckpLength , sizeof (CK_CHAR ));
688
+ if (* ckpArray == NULL && * ckpLength != 0UL ) {
685
689
free (jpTemp );
686
690
p11ThrowOutOfMemoryError (env , 0 );
687
691
return ;
@@ -705,13 +709,14 @@ void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CH
705
709
jchar * jTemp ;
706
710
CK_ULONG i ;
707
711
708
- * ckpLength = jArray == NULL ? 0L : (* env )-> GetArrayLength (env , jArray );
709
- if (* ckpLength == 0L ) {
712
+ if (jArray == NULL ) {
710
713
* ckpArray = NULL_PTR ;
714
+ * ckpLength = 0UL ;
711
715
return ;
712
716
}
717
+ * ckpLength = (* env )-> GetArrayLength (env , jArray );
713
718
jTemp = (jchar * ) calloc (* ckpLength , sizeof (jchar ));
714
- if (jTemp == NULL ) {
719
+ if (jTemp == NULL && * ckpLength != 0UL ) {
715
720
p11ThrowOutOfMemoryError (env , 0 );
716
721
return ;
717
722
}
@@ -721,7 +726,7 @@ void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CH
721
726
}
722
727
723
728
* ckpArray = (CK_UTF8CHAR_PTR ) calloc (* ckpLength , sizeof (CK_UTF8CHAR ));
724
- if (* ckpArray == NULL ) {
729
+ if (* ckpArray == NULL && * ckpLength != 0UL ) {
725
730
p11ThrowOutOfMemoryError (env , 0 );
726
731
goto cleanup ;
727
732
}
@@ -792,7 +797,7 @@ void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jArray, CK_ATTR
792
797
jLength = (* env )-> GetArrayLength (env , jArray );
793
798
* ckpLength = jLongToCKULong (jLength );
794
799
* ckpArray = (CK_ATTRIBUTE_PTR ) calloc (* ckpLength , sizeof (CK_ATTRIBUTE ));
795
- if (* ckpArray == NULL ) {
800
+ if (* ckpArray == NULL && * ckpLength != 0UL ) {
796
801
p11ThrowOutOfMemoryError (env , 0 );
797
802
return ;
798
803
}
@@ -833,7 +838,7 @@ jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_U
833
838
jpTemp = (jbyte * ) ckpArray ;
834
839
} else {
835
840
jpTemp = (jbyte * ) calloc (ckLength , sizeof (jbyte ));
836
- if (jpTemp == NULL ) {
841
+ if (jpTemp == NULL && ckLength != 0UL ) {
837
842
p11ThrowOutOfMemoryError (env , 0 );
838
843
return NULL ;
839
844
}
@@ -867,7 +872,7 @@ jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK
867
872
jlongArray jArray ;
868
873
869
874
jpTemp = (jlong * ) calloc (ckLength , sizeof (jlong ));
870
- if (jpTemp == NULL ) {
875
+ if (jpTemp == NULL && ckLength != 0UL ) {
871
876
p11ThrowOutOfMemoryError (env , 0 );
872
877
return NULL ;
873
878
}
@@ -898,7 +903,7 @@ jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_U
898
903
jcharArray jArray ;
899
904
900
905
jpTemp = (jchar * ) calloc (ckLength , sizeof (jchar ));
901
- if (jpTemp == NULL ) {
906
+ if (jpTemp == NULL && ckLength != 0UL ) {
902
907
p11ThrowOutOfMemoryError (env , 0 );
903
908
return NULL ;
904
909
}
@@ -929,7 +934,7 @@ jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArr
929
934
jcharArray jArray ;
930
935
931
936
jpTemp = (jchar * ) calloc (ckLength , sizeof (jchar ));
932
- if (jpTemp == NULL ) {
937
+ if (jpTemp == NULL && ckLength != 0UL ) {
933
938
p11ThrowOutOfMemoryError (env , 0 );
934
939
return NULL ;
935
940
}
0 commit comments