changeset 60152:96d78010ed9f

8239139: test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/libInheritedChannel.c does not compile with gcc 8.3.1 Reviewed-by: michaelm Contributed-by: linzang@tencent.com
author michaelm
date Wed, 19 Feb 2020 11:31:48 +0000
parents 80e403e1ff94
children 81133b1ca410
files test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/libInheritedChannel.c
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/libInheritedChannel.c	Wed Feb 19 10:34:42 2020 +0000
+++ b/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/libInheritedChannel.c	Wed Feb 19 11:31:48 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -233,10 +233,12 @@
     struct sockaddr_un addr;
     const char *nameUtf = (*env)->GetStringUTFChars(env, name, NULL);
     int ret = -1;
+    int length = sizeof(addr.sun_path);
     unlink(nameUtf);
     memset(&addr, 0, sizeof(addr));
     addr.sun_family = AF_UNIX;
-    strncpy(addr.sun_path, nameUtf, strlen(nameUtf));
+    strncpy(addr.sun_path, nameUtf, length);
+    addr.sun_path[length - 1] = '\0';
     ret = bind(sock, (const struct sockaddr*)&addr, sizeof(addr));
     if (ret == -1) {
         ThrowException(env, "java/io/IOException", "socket bind error");
@@ -265,9 +267,11 @@
     struct sockaddr_un addr;
     const char *nameUtf = (*env)->GetStringUTFChars(env, name, NULL);
     int ret = -1;
+    int length = sizeof(addr.sun_path);
     memset(&addr, 0, sizeof(addr));
     addr.sun_family = AF_UNIX;
-    strncpy(addr.sun_path, nameUtf, strlen(nameUtf));
+    strncpy(addr.sun_path, nameUtf, length);
+    addr.sun_path[length - 1] = '\0';
     ret = connect(fd, (const struct sockaddr*)&addr, sizeof(addr));
     if (ret == -1) {
         ThrowException(env, "java/io/IOException", "socket connect error");