< prev index next >
src/share/vm/runtime/arguments.cpp
Print this page
rev 8113 : 8076475: Misuses of strncpy/strncat
Summary: Various small fixes around strncpy and strncat
Reviewed-by: dsamersoff
@@ -2703,11 +2703,11 @@
char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len);
name[len] = '\0';
char *options = NULL;
if(pos != NULL) {
- options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1, mtInternal), pos + 1);
+ options = os::strdup_check_oom(pos + 1, mtInternal);
}
#if !INCLUDE_JVMTI
if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) {
jio_fprintf(defaultStream::error_stream(),
"Profiling and debugging agents are not supported in this VM\n");
@@ -3294,12 +3294,11 @@
// skip over all the leading empty paths
while (*src == separator) {
src ++;
}
- char* copy = AllocateHeap(strlen(src) + 1, mtInternal);
- strncpy(copy, src, strlen(src) + 1);
+ char* copy = os::strdup_check_oom(src, mtInternal);
// trim all trailing empty paths
for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
*tail = '\0';
}
@@ -3460,13 +3459,11 @@
if (!add_property("java.awt.headless=true")) {
return JNI_ENOMEM;
}
} else {
char buffer[256];
- const char *key = "java.awt.headless=";
- strcpy(buffer, key);
- strncat(buffer, headless_env, 256 - strlen(key) - 1);
+ jio_snprintf(buffer, sizeof(buffer), "java.awt.headless=%s", headless_env);
if (!add_property(buffer)) {
return JNI_ENOMEM;
}
}
}
@@ -3625,22 +3622,18 @@
os::jvm_path(jvm_path, sizeof(jvm_path));
char *end = strrchr(jvm_path, *os::file_separator());
if (end != NULL) *end = '\0';
size_t jvm_path_len = strlen(jvm_path);
size_t file_sep_len = strlen(os::file_separator());
- shared_archive_path = NEW_C_HEAP_ARRAY(char, jvm_path_len +
- file_sep_len + 20, mtInternal);
+ const size_t len = jvm_path_len + file_sep_len + 20;
+ shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtInternal);
if (shared_archive_path != NULL) {
- strncpy(shared_archive_path, jvm_path, jvm_path_len + 1);
- strncat(shared_archive_path, os::file_separator(), file_sep_len);
- strncat(shared_archive_path, "classes.jsa", 11);
+ jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa",
+ jvm_path, os::file_separator());
}
} else {
- shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(SharedArchiveFile) + 1, mtInternal);
- if (shared_archive_path != NULL) {
- strncpy(shared_archive_path, SharedArchiveFile, strlen(SharedArchiveFile) + 1);
- }
+ shared_archive_path = os::strdup_check_oom(SharedArchiveFile, mtInternal);
}
return shared_archive_path;
}
#ifndef PRODUCT
< prev index next >