From: Frederic Suter Date: Tue, 21 Mar 2017 12:03:38 +0000 (+0100) Subject: partially address a bug in Java initialization X-Git-Tag: v3_15~30^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ef1b10a74dde75e195d7897449975b6834f3cb06?ds=sidebyside partially address a bug in Java initialization SimGrid flag on command line were consumed at C level but stayed in the original Java String[] args. This could mess users' args[i] if SG flags were not put at the end of the command line. This patch removes the SG flags from the Java arguments. However, the number of arguments REMAINS UNCHANGED. It is then UNSAFE to test if args.length is greater than the number of YOUR OWN ARGUMENTS. It might be if you have --log or --cfg flags in the command line. BTW, it already was ... --- diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index b6c17012b3..7ffbb238d1 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -115,7 +115,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j setlocale(LC_NUMERIC,"C"); if (jargs) - argc = (int) env->GetArrayLength(jargs); + argc = static_cast(env->GetArrayLength(jargs)); argc++; argv = xbt_new(char *, argc + 1); @@ -134,9 +134,11 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j JAVA_HOST_LEVEL = simgrid::s4u::Host::extension_create(__JAVA_host_priv_free); JAVA_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, __JAVA_storage_priv_free); - for (index = 0; index < argc; index++) + for (index = 0; index < argc - 1; index++) { + env->SetObjectArrayElement(jargs, index, (jstring)env->NewStringUTF(argv[index + 1])); free(argv[index]); - + } + free(argv[argc]); free(argv); }