8155968: Update command line options

Reviewed-by: gthornbr, hseigel, mschoene
This commit is contained in:
Gerard Ziemski 2016-06-09 13:47:15 -05:00 committed by Gerard Ziemski
parent 065f9a3a4e
commit 656510aa27

View File

@ -794,9 +794,10 @@ static bool append_to_string_flag(const char* name, const char* new_value, Flag:
} else if (new_len == 0) {
value = old_value;
} else {
char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtArguments);
size_t length = old_len + 1 + new_len + 1;
char* buf = NEW_C_HEAP_ARRAY(char, length, mtArguments);
// each new setting adds another LINE to the switch:
sprintf(buf, "%s\n%s", old_value, new_value);
jio_snprintf(buf, length, "%s\n%s", old_value, new_value);
value = buf;
free_this_too = buf;
}
@ -1014,15 +1015,17 @@ const char* Arguments::build_resource_string(char** args, int count) {
if (args == NULL || count == 0) {
return NULL;
}
size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
for (int i = 1; i < count; i++) {
length += strlen(args[i]) + 1; // add 1 for a space
size_t length = 0;
for (int i = 0; i < count; i++) {
length += strlen(args[i]) + 1; // add 1 for a space or NULL terminating character
}
char* s = NEW_RESOURCE_ARRAY(char, length);
strcpy(s, args[0]);
for (int j = 1; j < count; j++) {
strcat(s, " ");
strcat(s, args[j]);
char* dst = s;
for (int j = 0; j < count; j++) {
size_t offset = strlen(args[j]) + 1; // add 1 for a space or NULL terminating character
jio_snprintf(dst, length, "%s ", args[j]); // jio_snprintf will replace the last space character with NULL character
dst += offset;
length -= offset;
}
return (const char*) s;
}
@ -1106,9 +1109,8 @@ bool Arguments::process_argument(const char* arg,
// Only make the obsolete check for valid arguments.
if (arg_len <= BUFLEN) {
// Construct a string which consists only of the argument name without '+', '-', or '='.
char stripped_argname[BUFLEN+1];
strncpy(stripped_argname, argname, arg_len);
stripped_argname[arg_len] = '\0'; // strncpy may not null terminate.
char stripped_argname[BUFLEN+1]; // +1 for '\0'
jio_snprintf(stripped_argname, arg_len+1, "%s", argname); // +1 for '\0'
if (is_obsolete_flag(stripped_argname, &since)) {
char version[256];
since.to_string(version, sizeof(version));
@ -1260,8 +1262,7 @@ bool Arguments::add_property(const char* prop, PropertyWriteable writeable, Prop
size_t key_len = eq - prop;
char* tmp_key = AllocateHeap(key_len + 1, mtArguments);
strncpy(tmp_key, prop, key_len);
tmp_key[key_len] = '\0';
jio_snprintf(tmp_key, key_len + 1, "%s", prop);
key = tmp_key;
value = &prop[key_len + 1];
@ -2256,7 +2257,7 @@ jint Arguments::set_aggressive_opts_flags() {
// Feed the cache size setting into the JDK
char buffer[1024];
sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
jio_snprintf(buffer, 1024, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
if (!add_property(buffer)) {
return JNI_ENOMEM;
}
@ -2777,8 +2778,8 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
if (tail != NULL) {
const char* pos = strchr(tail, ':');
size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1, mtArguments), tail, len);
name[len] = '\0';
char* name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
jio_snprintf(name, len + 1, "%s", tail);
char *options = NULL;
if(pos != NULL) {
@ -2854,7 +2855,9 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
return JNI_ERR;
#else
if (tail != NULL) {
char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtArguments), tail);
size_t length = strlen(tail) + 1;
char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
jio_snprintf(options, length, "%s", tail);
add_init_agent("instrument", options, false);
// java agents need module java.instrument
if (!create_numbered_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
@ -3512,7 +3515,7 @@ jint Arguments::finalize_vm_init_args() {
// check if the default lib/endorsed directory exists; if so, error
char path[JVM_MAXPATHLEN];
const char* fileSep = os::file_separator();
sprintf(path, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
if (CheckEndorsedAndExtDirs) {
int nonEmptyDirs = 0;
@ -3534,7 +3537,7 @@ jint Arguments::finalize_vm_init_args() {
return JNI_ERR;
}
sprintf(path, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
dir = os::opendir(path);
if (dir != NULL) {
jio_fprintf(defaultStream::output_stream(),