diff --git a/src/java.base/share/native/libjli/java.c b/src/java.base/share/native/libjli/java.c index 62d859c0d4f..eb519e4e51e 100644 --- a/src/java.base/share/native/libjli/java.c +++ b/src/java.base/share/native/libjli/java.c @@ -1007,7 +1007,7 @@ SelectVersion(int argc, char **argv, char **main_class) argc--; argv++; - while ((arg = *argv) != 0 && *arg == '-') { + while (argc > 0 && *(arg = *argv) == '-') { has_arg = IsOptionWithArgument(argc, argv); if (JLI_StrCCmp(arg, "-version:") == 0) { JLI_ReportErrorMessage(SPC_ERROR1); @@ -1209,7 +1209,7 @@ ParseArguments(int *pargc, char ***pargv, *pret = 0; - while ((arg = *argv) != 0 && *arg == '-') { + while (argc > 0 && *(arg = *argv) == '-') { char *option = NULL; char *value = NULL; int kind = GetOpt(&argc, &argv, &option, &value); diff --git a/test/jdk/tools/launcher/JliLaunchTest.java b/test/jdk/tools/launcher/JliLaunchTest.java index 367b3994407..13df6410e89 100644 --- a/test/jdk/tools/launcher/JliLaunchTest.java +++ b/test/jdk/tools/launcher/JliLaunchTest.java @@ -24,7 +24,7 @@ /** * @test - * @bug 8213362 8238225 + * @bug 8213362 8238225 8303669 * @comment Test JLI_Launch for tools distributed outside JDK * @library /test/lib * @run main/native JliLaunchTest diff --git a/test/jdk/tools/launcher/exeJliLaunchTest.c b/test/jdk/tools/launcher/exeJliLaunchTest.c index 5c6b597101b..d012421d100 100644 --- a/test/jdk/tools/launcher/exeJliLaunchTest.c +++ b/test/jdk/tools/launcher/exeJliLaunchTest.c @@ -33,8 +33,14 @@ #include "java.h" int -main(int argc, char **argv) +main(int argc, char **args) { + //avoid null-terminated array of arguments to test JDK-8303669 + char *argv[argc]; + for (int i = 0; i < argc; i++) { + argv[i] = args[i]; + } + return JLI_Launch(argc, argv, 0, NULL, 0, NULL,