Skip to content

Commit 82eb558

Browse files
authored
Fix unused return value warnings which manifest as errors. (#1396)
This should be the correct fix for the build issues that came up on recent ECH changes. Background: Unless you install Clang and take steps to make it the default compiler, then on many Linux distributions (esp Ubuntu) the JNI code will get built with gcc. gcc does not consider casting to void is sufficient to avoid a warning about unused returns from a function which has the warn_unused_result attribute. This change assigns the result to a variable with the CONSCRYPT_UNUSED attribute which works correctly on Clang, gcc and MSVC. As for why it's OK in these cases: The asprintf methods should probably *not* ignore the value but they're calling FatalError with the result so it's game over anyway. This method could use re-writing but not this PR. The read and write on fdsEmergency in native_crypto is part of an "interesting" mechanism to prevent blocking forever when using the ConscryptFileDescriptorSocket implementation, which ought to go away but works as-is.
1 parent ca3320d commit 82eb558

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

common/src/jni/main/cpp/conscrypt/jniutil.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,15 @@ void jniRegisterNativeMethods(JNIEnv* env, const char* className, const JNINativ
159159
ScopedLocalRef<jclass> c(env, env->FindClass(className));
160160
if (c.get() == nullptr) {
161161
char* msg;
162-
(void)asprintf(&msg, "Native registration unable to find class '%s'; aborting...",
163-
className);
162+
CONSCRYPT_UNUSED int n = asprintf(
163+
&msg, "Native registration unable to find class '%s'; aborting...", className);
164164
env->FatalError(msg);
165165
}
166166

167167
if (env->RegisterNatives(c.get(), gMethods, numMethods) < 0) {
168168
char* msg;
169-
(void)asprintf(&msg, "RegisterNatives failed for '%s'; aborting...", className);
169+
CONSCRYPT_UNUSED int n =
170+
asprintf(&msg, "RegisterNatives failed for '%s'; aborting...", className);
170171
env->FatalError(msg);
171172
}
172173
}

common/src/jni/main/cpp/conscrypt/native_crypto.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7835,7 +7835,7 @@ static int sslSelect(JNIEnv* env, int type, jobject fdObject, AppData* appData,
78357835
if (fds[1].revents & POLLIN) {
78367836
char token;
78377837
do {
7838-
(void)read(appData->fdsEmergency[0], &token, 1);
7838+
CONSCRYPT_UNUSED int n = read(appData->fdsEmergency[0], &token, 1);
78397839
} while (errno == EINTR);
78407840
}
78417841
}
@@ -7866,7 +7866,7 @@ static void sslNotify(AppData* appData) {
78667866
char token = '*';
78677867
do {
78687868
errno = 0;
7869-
(void)write(appData->fdsEmergency[1], &token, 1);
7869+
CONSCRYPT_UNUSED int n = write(appData->fdsEmergency[1], &token, 1);
78707870
} while (errno == EINTR);
78717871
errno = errnoBackup;
78727872
#endif

0 commit comments

Comments
 (0)