Skip to content

Commit

Permalink
8254871: Remove unnecessary string copy in NetworkInterface.c
Browse files Browse the repository at this point in the history
Reviewed-by: michaelm
  • Loading branch information
Eric Liu authored and nick-arm committed Oct 28, 2020
1 parent acd0e25 commit a804c6a
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/java.base/unix/native/libnet/NetworkInterface.c
Original file line number Diff line number Diff line change
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

1 comment on commit a804c6a

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on a804c6a Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.