src/share/vm/runtime/arguments.cpp

changeset 8553
e73d79ce00e4
parent 8544
872c3a32dba4
child 8604
04d83ba48607
child 8712
c7140a91e56a
equal deleted inserted replaced
8552:b5f2f874db7c 8553:e73d79ce00e4
558 const char* ext = name + strlen(name) - 4; 558 const char* ext = name + strlen(name) - 4;
559 bool isJarOrZip = ext > name && 559 bool isJarOrZip = ext > name &&
560 (os::file_name_strcmp(ext, ".jar") == 0 || 560 (os::file_name_strcmp(ext, ".jar") == 0 ||
561 os::file_name_strcmp(ext, ".zip") == 0); 561 os::file_name_strcmp(ext, ".zip") == 0);
562 if (isJarOrZip) { 562 if (isJarOrZip) {
563 char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name), mtInternal); 563 size_t length = directory_len + 2 + strlen(name);
564 sprintf(jarpath, "%s%s%s", directory, dir_sep, name); 564 char* jarpath = NEW_C_HEAP_ARRAY(char, length, mtInternal);
565 jio_snprintf(jarpath, length, "%s%s%s", directory, dir_sep, name);
565 path = add_to_path(path, jarpath, false); 566 path = add_to_path(path, jarpath, false);
566 FREE_C_HEAP_ARRAY(char, jarpath, mtInternal); 567 FREE_C_HEAP_ARRAY(char, jarpath, mtInternal);
567 } 568 }
568 } 569 }
569 FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); 570 FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
702 if (old_len == 0) { 703 if (old_len == 0) {
703 value = new_value; 704 value = new_value;
704 } else if (new_len == 0) { 705 } else if (new_len == 0) {
705 value = old_value; 706 value = old_value;
706 } else { 707 } else {
707 char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtInternal); 708 size_t length = old_len + 1 + new_len + 1;
709 char* buf = NEW_C_HEAP_ARRAY(char, length, mtInternal);
708 // each new setting adds another LINE to the switch: 710 // each new setting adds another LINE to the switch:
709 sprintf(buf, "%s\n%s", old_value, new_value); 711 jio_snprintf(buf, length, "%s\n%s", old_value, new_value);
710 value = buf; 712 value = buf;
711 free_this_too = buf; 713 free_this_too = buf;
712 } 714 }
713 (void) CommandLineFlags::ccstrAtPut(name, &value, origin); 715 (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
714 // CommandLineFlags always returns a pointer that needs freeing. 716 // CommandLineFlags always returns a pointer that needs freeing.
811 // strings in a given char** array 813 // strings in a given char** array
812 const char* Arguments::build_resource_string(char** args, int count) { 814 const char* Arguments::build_resource_string(char** args, int count) {
813 if (args == NULL || count == 0) { 815 if (args == NULL || count == 0) {
814 return NULL; 816 return NULL;
815 } 817 }
816 size_t length = strlen(args[0]) + 1; // add 1 for the null terminator 818 size_t length = 0;
817 for (int i = 1; i < count; i++) { 819 for (int i = 0; i < count; i++) {
818 length += strlen(args[i]) + 1; // add 1 for a space 820 length += strlen(args[i]) + 1; // add 1 for a space or NULL terminating character
819 } 821 }
820 char* s = NEW_RESOURCE_ARRAY(char, length); 822 char* s = NEW_RESOURCE_ARRAY(char, length);
821 strcpy(s, args[0]); 823 char* dst = s;
822 for (int j = 1; j < count; j++) { 824 for (int j = 0; j < count; j++) {
823 strcat(s, " "); 825 size_t offset = strlen(args[j]) + 1; // add 1 for a space or NULL terminating character
824 strcat(s, args[j]); 826 jio_snprintf(dst, length, "%s ", args[j]); // jio_snprintf will replace the last space character with NULL character
827 dst += offset;
828 length -= offset;
825 } 829 }
826 return (const char*) s; 830 return (const char*) s;
827 } 831 }
828 832
829 void Arguments::print_on(outputStream* st) { 833 void Arguments::print_on(outputStream* st) {
1887 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000); 1891 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
1888 } 1892 }
1889 1893
1890 // Feed the cache size setting into the JDK 1894 // Feed the cache size setting into the JDK
1891 char buffer[1024]; 1895 char buffer[1024];
1892 sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax); 1896 jio_snprintf(buffer, 1024, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
1893 add_property(buffer); 1897 add_property(buffer);
1894 } 1898 }
1895 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) { 1899 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
1896 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500); 1900 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
1897 } 1901 }
2762 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2766 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len);
2763 name[len] = '\0'; 2767 name[len] = '\0';
2764 2768
2765 char *options = NULL; 2769 char *options = NULL;
2766 if(pos != NULL) { 2770 if(pos != NULL) {
2767 options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1, mtInternal), pos + 1); 2771 size_t length = strlen(pos + 1) + 1;
2772 options = NEW_C_HEAP_ARRAY(char, length, mtInternal);
2773 jio_snprintf(options, length, "%s", pos + 1);
2768 } 2774 }
2769 #if !INCLUDE_JVMTI 2775 #if !INCLUDE_JVMTI
2770 if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) { 2776 if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) {
2771 jio_fprintf(defaultStream::error_stream(), 2777 jio_fprintf(defaultStream::error_stream(),
2772 "Profiling and debugging agents are not supported in this VM\n"); 2778 "Profiling and debugging agents are not supported in this VM\n");
2781 jio_fprintf(defaultStream::error_stream(), 2787 jio_fprintf(defaultStream::error_stream(),
2782 "Instrumentation agents are not supported in this VM\n"); 2788 "Instrumentation agents are not supported in this VM\n");
2783 return JNI_ERR; 2789 return JNI_ERR;
2784 #else 2790 #else
2785 if(tail != NULL) { 2791 if(tail != NULL) {
2786 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtInternal), tail); 2792 size_t length = strlen(tail) + 1;
2793 char *options = NEW_C_HEAP_ARRAY(char, length, mtInternal);
2794 jio_snprintf(options, length, "%s", tail);
2787 add_init_agent("instrument", options, false); 2795 add_init_agent("instrument", options, false);
2788 } 2796 }
2789 #endif // !INCLUDE_JVMTI 2797 #endif // !INCLUDE_JVMTI
2790 // -Xnoclassgc 2798 // -Xnoclassgc
2791 } else if (match_option(option, "-Xnoclassgc", &tail)) { 2799 } else if (match_option(option, "-Xnoclassgc", &tail)) {
3619 if (!add_property("java.awt.headless=true")) { 3627 if (!add_property("java.awt.headless=true")) {
3620 return JNI_ENOMEM; 3628 return JNI_ENOMEM;
3621 } 3629 }
3622 } else { 3630 } else {
3623 char buffer[256]; 3631 char buffer[256];
3624 strcpy(buffer, "java.awt.headless="); 3632 jio_snprintf(buffer, 256, "java.awt.headless=%s", envbuffer);
3625 strcat(buffer, envbuffer);
3626 if (!add_property(buffer)) { 3633 if (!add_property(buffer)) {
3627 return JNI_ENOMEM; 3634 return JNI_ENOMEM;
3628 } 3635 }
3629 } 3636 }
3630 } 3637 }

mercurial