From e400dc061ddbd505bbb4f3fe9797682e314717fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20B=C3=A9langer?= Date: Wed, 23 Oct 2019 15:40:42 -0700 Subject: Silence unguarded availability warnings for `getentropy` when targeting macOS 10.12 (#5019) * silence `Wunguarded-availability` when building with a `MACOSX_DEPLOYMENT_TARGET < 10.12` * use `__builtin_available` rather than a `NULL` echo upon init on mac --- src/_cffi_src/openssl/src/osrandom_engine.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/_cffi_src/openssl/src/osrandom_engine.c b/src/_cffi_src/openssl/src/osrandom_engine.c index 1b893ec7..dc7b1d5e 100644 --- a/src/_cffi_src/openssl/src/osrandom_engine.c +++ b/src/_cffi_src/openssl/src/osrandom_engine.c @@ -251,7 +251,7 @@ static int osrandom_init(ENGINE *e) { #if !defined(__APPLE__) getentropy_works = CRYPTOGRAPHY_OSRANDOM_GETENTROPY_WORKS; #else - if (&getentropy != NULL) { + if (__builtin_available(macOS 10.12, *)) { getentropy_works = CRYPTOGRAPHY_OSRANDOM_GETENTROPY_WORKS; } else { getentropy_works = CRYPTOGRAPHY_OSRANDOM_GETENTROPY_FALLBACK; @@ -277,7 +277,11 @@ static int osrandom_rand_bytes(unsigned char *buffer, int size) { while (size > 0) { /* OpenBSD and macOS restrict maximum buffer size to 256. */ len = size > 256 ? 256 : size; +/* on mac, availability is already checked using `__builtin_available` above */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" res = getentropy(buffer, (size_t)len); +#pragma clang diagnostic pop if (res < 0) { ERR_Cryptography_OSRandom_error( CRYPTOGRAPHY_OSRANDOM_F_RAND_BYTES, -- cgit v1.2.3