Skip to content

Commit d7e0a97

Browse files
Fix build: Initialize saveptr to NULL and ensure pathElement is checked for NULL early
1 parent 644b708 commit d7e0a97

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

native/dispatch.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -3143,19 +3143,23 @@ Java_com_sun_jna_Native_getWindowHandle0(JNIEnv* UNUSED_JAWT(env), jclass UNUSED
31433143
if (jprop != NULL) {
31443144

31453145
char* prop = newCString(env, jprop);
3146-
char* saveptr;
3146+
char* saveptr = NULL;
31473147

31483148
for(char* propToBeTokeninzed = prop; ; propToBeTokeninzed = NULL) {
31493149
char* pathElement = strtok_r(propToBeTokeninzed, ":", &saveptr);
31503150

3151+
if(pathElement == NULL) {
3152+
break;
3153+
}
3154+
31513155
size_t len = strlen(pathElement) + strlen(jawtLibraryName) + 2;
31523156
char* path = (char*) alloca(len);
31533157

31543158
sprintf(path, "%s/%s", pathElement, jawtLibraryName);
31553159

31563160
jawt_handle = LOAD_LIBRARY(path, DEFAULT_LOAD_OPTS);
3157-
if(jawt_handle != NULL || pathElement == NULL) {
3158-
break;
3161+
if(jawt_handle != NULL) {
3162+
break;
31593163
}
31603164
}
31613165

0 commit comments

Comments
 (0)