From c01cb1d685b70bc9ef102e08eba6ea3e928ae59c Mon Sep 17 00:00:00 2001 From: liaotonglang Date: Tue, 10 Jan 2023 11:20:24 +0800 Subject: [PATCH] Fix ignoring return value of arc4random() warning (with _FORTIFY_SOURCE defined) arc4random() defines with __wur (warn-unused-return) macro in glibc, but the problem pops up only for gentoo, since only it really define __wur to __attribute__ ((__warn_unused_result__)), because it defines _FORTIFY_SOURCE unconditionally [1]. [1]: https://gitweb.gentoo.org/proj/gcc-patches.git/tree/9.4.0/gentoo/01_all_default-fortify-source.patch?id=7f7f80a650607c3090ae0790b8daef88434da681 And hence you get this error: ```sh docker run -v $PWD:/src:ro --rm --name le -w /src -it gentoo/stage3 bash -c 'mkdir /build && cd /build && /src/configure --enable-gcc-warnings=yes --disable-samples && make -j && echo OK' /src/evutil_rand.c: In function 'evutil_secure_rng_init': /src/evutil_rand.c:56:16: error: ignoring return value of 'arc4random' declared with attribute 'warn_unused_result' [-Werror=unused-result] 56 | (void) arc4random(); | ^~~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [Makefile:2056: evutil_rand.lo] Error 1 make[1]: *** Waiting for unfinished jobs.... make[1]: Leaving directory '/build' make: *** [Makefile:1523: all] Error 2 ``` Also it seems that GCC works as expected here [2], and will not change the behavior. [2]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 --- evutil_rand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evutil_rand.c b/evutil_rand.c index 8e9afdaa..139d0d03 100644 --- a/evutil_rand.c +++ b/evutil_rand.c @@ -53,7 +53,7 @@ int evutil_secure_rng_init(void) { /* call arc4random() now to force it to self-initialize */ - (void) arc4random(); + (void)! arc4random(); return 0; } #ifndef EVENT__DISABLE_THREAD_SUPPORT