From d7e0a977d0d4d463b33c417ed7fd8f9389d41071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Mon, 14 Mar 2022 21:19:36 +0100 Subject: [PATCH] Fix build: Initialize saveptr to NULL and ensure pathElement is checked for NULL early --- native/dispatch.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/native/dispatch.c b/native/dispatch.c index 930ccebf05..6d104f8778 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -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; } }