Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8254871: Remove unnecessary string copy in NetworkInterface.c #821

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/java.base/unix/native/libnet/NetworkInterface.c
Expand Up @@ -205,7 +205,6 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0
jboolean isCopy;
const char* name_utf;
char *colonP;
char searchName[IFNAMESIZE];
jobject obj = NULL;

if (name != NULL) {
Expand All @@ -229,15 +228,11 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0

// search the list of interfaces based on name,
// if it is virtual sub interface search with parent first.
strncpy(searchName, name_utf, IFNAMESIZE);
searchName[IFNAMESIZE - 1] = '\0';
colonP = strchr(searchName, ':');
if (colonP != NULL) {
*colonP = '\0';
}
colonP = strchr(name_utf, ':');
size_t limit = colonP != NULL ? (size_t)(colonP - name_utf) : strlen(name_utf);
curr = ifs;
while (curr != NULL) {
if (strcmp(searchName, curr->name) == 0) {
if (strlen(curr->name) == limit && memcmp(name_utf, curr->name, limit) == 0) {
break;
}
curr = curr->next;
Expand Down