Skip to content

Commit b122119

Browse files
caojoshuaRealCLanger
authored andcommitted
8252051: Make mlvmJvmtiUtils strncpy uses GCC 10.x friendly
Reviewed-by: phh
1 parent 2847e34 commit b122119

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ void copyFromJString(JNIEnv * pEnv, jstring src, char ** dst) {
4545
NSK_CPP_STUB3(ReleaseStringUTFChars, pEnv, src, pStr);
4646
}
4747

48-
#if !defined(__clang_major__) && defined(__GNUC__) && (__GNUC__ >= 8)
49-
_Pragma("GCC diagnostic push")
50-
_Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"")
51-
#endif
52-
5348
struct MethodName * getMethodName(jvmtiEnv * pJvmtiEnv, jmethodID method) {
5449
char * szName;
5550
char * szSignature;
@@ -71,18 +66,16 @@ struct MethodName * getMethodName(jvmtiEnv * pJvmtiEnv, jmethodID method) {
7166
}
7267

7368
mn = malloc(sizeof(MethodNameStruct));
74-
strncpy(mn->methodName, szName, sizeof(mn->methodName));
75-
strncpy(mn->classSig, szSignature, sizeof(mn->classSig));
69+
strncpy(mn->methodName, szName, sizeof(mn->methodName) - 1);
70+
mn->methodName[sizeof(mn->methodName) - 1] = '\0';
71+
strncpy(mn->classSig, szSignature, sizeof(mn->classSig) - 1);
72+
mn->classSig[sizeof(mn->classSig) - 1] = '\0';
7673

7774
NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (void *) szName));
7875
NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (void *) szSignature));
7976
return mn;
8077
}
8178

82-
#if !defined(__clang_major__) && defined(__GNUC__) && (__GNUC__ >= 8)
83-
_Pragma("GCC diagnostic pop")
84-
#endif
85-
8679
char * locationToString(jvmtiEnv * pJvmtiEnv, jmethodID method, jlocation location) {
8780
struct MethodName * pMN;
8881
// gcc 7.3 claims that snprintf below can output between 6 and 531 bytes. Setting buffer size to 600.

0 commit comments

Comments
 (0)