Skip to content

Commit

Permalink
Merge pull request #1424 from matthiasblaesing/fix_build
Browse files Browse the repository at this point in the history
Fix build: Initialize saveptr to NULL and ensure pathElement is check…
  • Loading branch information
matthiasblaesing authored Mar 14, 2022
2 parents 644b708 + d7e0a97 commit c5ffcc5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions native/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3143,19 +3143,23 @@ Java_com_sun_jna_Native_getWindowHandle0(JNIEnv* UNUSED_JAWT(env), jclass UNUSED
if (jprop != NULL) {

char* prop = newCString(env, jprop);
char* saveptr;
char* saveptr = NULL;

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

if(pathElement == NULL) {
break;
}

size_t len = strlen(pathElement) + strlen(jawtLibraryName) + 2;
char* path = (char*) alloca(len);

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

jawt_handle = LOAD_LIBRARY(path, DEFAULT_LOAD_OPTS);
if(jawt_handle != NULL || pathElement == NULL) {
break;
if(jawt_handle != NULL) {
break;
}
}

Expand Down

0 comments on commit c5ffcc5

Please sign in to comment.