Skip to content

Commit a804c6a

Browse files
Eric Liunick-arm
Eric Liu
authored andcommitted
8254871: Remove unnecessary string copy in NetworkInterface.c
Reviewed-by: michaelm
1 parent acd0e25 commit a804c6a

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/java.base/unix/native/libnet/NetworkInterface.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0
205205
jboolean isCopy;
206206
const char* name_utf;
207207
char *colonP;
208-
char searchName[IFNAMESIZE];
209208
jobject obj = NULL;
210209

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

230229
// search the list of interfaces based on name,
231230
// if it is virtual sub interface search with parent first.
232-
strncpy(searchName, name_utf, IFNAMESIZE);
233-
searchName[IFNAMESIZE - 1] = '\0';
234-
colonP = strchr(searchName, ':');
235-
if (colonP != NULL) {
236-
*colonP = '\0';
237-
}
231+
colonP = strchr(name_utf, ':');
232+
size_t limit = colonP != NULL ? (size_t)(colonP - name_utf) : strlen(name_utf);
238233
curr = ifs;
239234
while (curr != NULL) {
240-
if (strcmp(searchName, curr->name) == 0) {
235+
if (strlen(curr->name) == limit && memcmp(name_utf, curr->name, limit) == 0) {
241236
break;
242237
}
243238
curr = curr->next;

0 commit comments

Comments
 (0)