8309216: Cast from jchar* to char* in test java/io/GetXSpace.java

Reviewed-by: rriggs, naoto
This commit is contained in:
Brian Burkhalter 2023-06-06 15:15:32 +00:00
parent d709c25cbf
commit 9188142698

View File

@ -60,8 +60,8 @@ Java_GetXSpace_getSpace0
{
jboolean totalSpaceIsEstimated = JNI_FALSE;
jlong array[4];
const jchar* chars = (*env)->GetStringChars(env, root, NULL);
if (chars == NULL) {
const jchar* strchars = (*env)->GetStringChars(env, root, NULL);
if (strchars == NULL) {
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
"GetStringChars");
return JNI_FALSE;
@ -77,12 +77,13 @@ Java_GetXSpace_getSpace0
}
}
LPCWSTR path = (LPCWSTR)chars;
LPCWSTR path = (LPCWSTR)strchars;
if (pfnGetDiskSpaceInformation != NULL) {
// use GetDiskSpaceInformationW
DISK_SPACE_INFORMATION diskSpaceInfo;
BOOL hres = pfnGetDiskSpaceInformation(path, &diskSpaceInfo);
(*env)->ReleaseStringChars(env, root, strchars);
if (FAILED(hres)) {
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
"GetDiskSpaceInformationW");
@ -108,8 +109,10 @@ Java_GetXSpace_getSpace0
ULARGE_INTEGER totalNumberOfBytes;
ULARGE_INTEGER totalNumberOfFreeBytes;
if (GetDiskFreeSpaceExW(path, &freeBytesAvailable, &totalNumberOfBytes,
&totalNumberOfFreeBytes) == 0) {
BOOL hres = GetDiskFreeSpaceExW(path, &freeBytesAvailable,
&totalNumberOfBytes, &totalNumberOfFreeBytes);
(*env)->ReleaseStringChars(env, root, strchars);
if (FAILED(hres)) {
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
"GetDiskFreeSpaceExW");
return totalSpaceIsEstimated;
@ -124,9 +127,24 @@ Java_GetXSpace_getSpace0
array[3] = (jlong)freeBytesAvailable.QuadPart;
}
#else
int len = (int)(*env)->GetStringLength(env, root);
char* chars = (char*)malloc((len + 1)*sizeof(char));
if (chars == NULL) {
(*env)->ReleaseStringChars(env, root, strchars);
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
"malloc");
return JNI_FALSE;
}
for (int i = 0; i < len; i++) {
chars[i] = (char)strchars[i];
}
chars[len] = '\0';
(*env)->ReleaseStringChars(env, root, strchars);
struct statfs buf;
int result = statfs((const char*)chars, &buf);
(*env)->ReleaseStringChars(env, root, chars);
free(chars);
if (result < 0) {
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
strerror(errno));