Skip to content

Commit

Permalink
native: Fix additional ExceptionChecks, and add EnsureLocalCapacity
Browse files Browse the repository at this point in the history
IBM Semeru found additional warnings with
-Xcheck:jni:warn,pedantic,advice

Oh hey, and ignore all these warnings from java/ and sun/ packages :-b
  • Loading branch information
kohlschuetter committed Jul 16, 2023
1 parent 1a0ad4e commit 6ee6f91
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions junixsocket-native/src/main/c/filedescriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ void _initFD(JNIEnv * env, jobject fd, jint handle)
if(fieldID_fd == NULL && methodID_setFd != NULL) {
// Android
(*env)->CallVoidMethod(env, fd, methodID_setFd, handle);
if((*env)->ExceptionCheck(env)) {
return;
}
return;
}

Expand Down
1 change: 1 addition & 0 deletions junixsocket-native/src/main/c/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jboolean supportsZeroLengthSend(void) {
JNIEXPORT void JNICALL Java_org_newsclub_net_unix_NativeUnixSocket_init
(JNIEnv *env, jclass clazz CK_UNUSED)
{
(*env)->EnsureLocalCapacity(env, 20);
#if defined(_WIN32)
WSADATA wsaData;
int ret = WSAStartup(MAKEWORD(2,2), &wsaData);
Expand Down
6 changes: 6 additions & 0 deletions junixsocket-native/src/main/c/receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ static ssize_t recvmsg_wrapper(JNIEnv * env, int handle, jbyte *buf, jint length
jmethodID kSetTipcErrorInfo = getMethodID_setTipcErrorInfo();
if(kSetTipcErrorInfo != NULL) {
(*env)->CallVoidMethod(env, ancSupp, kSetTipcErrorInfo, errInfo->errorCode, errInfo->dataLength);
if((*env)->ExceptionCheck(env)) {
return -1;
}
}
} else if(cmsg->cmsg_level == SOL_TIPC && cmsg->cmsg_type == TIPC_DESTNAME && len == 12) {
CK_IGNORE_CAST_ALIGN_BEGIN
Expand All @@ -189,6 +192,9 @@ static ssize_t recvmsg_wrapper(JNIEnv * env, int handle, jbyte *buf, jint length
jmethodID kSetTipcDestName = getMethodID_setTipcDestName();
if(kSetTipcDestName != NULL) {
(*env)->CallVoidMethod(env, ancSupp, kSetTipcDestName, addr->type, addr->lower, addr->upper);
if((*env)->ExceptionCheck(env)) {
return -1;
}
}
#endif
} else {
Expand Down
5 changes: 4 additions & 1 deletion junixsocket-native/src/main/c/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ JNIEXPORT jobject JNICALL Java_org_newsclub_net_unix_NativeUnixSocket_currentRMI
}
jobject connHandler = (*env)->CallObjectMethod(env, tl,
tlGet);
if(connHandler == NULL) {
if((*env)->ExceptionCheck(env) || connHandler == NULL) {
return NULL;
}
jclass connHandlerClass = (*env)->GetObjectClass(env, connHandler);
Expand Down Expand Up @@ -194,6 +194,9 @@ JNIEXPORT void JNICALL Java_org_newsclub_net_unix_NativeUnixSocket_deregisterSel
}
if(kMethodRemoveKey != NULL) {
(*env)->CallVoidMethod(env, chann, kMethodRemoveKey, key);
if((*env)->ExceptionCheck(env)) {
return;
}
} else {
// FIXME
}
Expand Down

0 comments on commit 6ee6f91

Please sign in to comment.