]> granicus.if.org Git - libevent/commit
Fix ignoring return value of arc4random() warning (with _FORTIFY_SOURCE defined)
authorliaotonglang <liaotonglang@gmail.com>
Tue, 10 Jan 2023 03:20:24 +0000 (11:20 +0800)
committerAzat Khuzhin <azat@libevent.org>
Sun, 22 Jan 2023 15:22:58 +0000 (16:22 +0100)
commitc01cb1d685b70bc9ef102e08eba6ea3e928ae59c
tree6e81cd96e1ed372977a0514ba290e3633c55eaa8
parent94cc08fde2c04cde3df2291f02631a26ccf27ee0
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