From 15df77f683ea944359210d5706a214b1c4ba4920 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 14 Jul 2017 12:21:17 -0700 Subject: Fix use of getentropy on larger blocks Found while working on suppressing the warning about the return value (which is either 0 or -1) was being ignored. Task-number: QTBUG-61968 Change-Id: I02d22222fff64d4dbda4fffd14d148b1724547ca Reviewed-by: Florian Bruhin Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/global/qrandom.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp index 6e368ac75b..3ab91eee20 100644 --- a/src/corelib/global/qrandom.cpp +++ b/src/corelib/global/qrandom.cpp @@ -81,6 +81,17 @@ DECLSPEC_IMPORT BOOLEAN WINAPI SystemFunction036(PVOID RandomBuffer, ULONG Rando # include #endif +// This file is too low-level for regular Q_ASSERT (the logging framework may +// recurse back), so use regular assert() +#undef NDEBUG +#undef Q_ASSERT_X +#undef Q_ASSERT +#define Q_ASSERT(cond) assert(cond) +#if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) +# define NDEBUG 1 +#endif +#include + QT_BEGIN_NAMESPACE #if defined(Q_PROCESSOR_X86) && QT_COMPILER_SUPPORTS_HERE(RDRND) @@ -126,10 +137,13 @@ public: qssize_t read = 0; while (count - read > 256) { // getentropy can't fail under normal circumstances - read += getentropy(reinterpret_cast(buffer) + read, 256); + int ret = getentropy(reinterpret_cast(buffer) + read, 256); + Q_ASSERT(ret == 0); + read += 256; } - getentropy(reinterpret_cast(buffer) + read, count - read); + int ret = getentropy(reinterpret_cast(buffer) + read, count - read); + Q_ASSERT(ret == 0); return count; } }; -- cgit v1.2.3