diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-07-14 12:21:17 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-07-27 23:19:05 +0000 |
commit | 15df77f683ea944359210d5706a214b1c4ba4920 (patch) | |
tree | 991d7ee3dfdcfd2dc3aed182747dcfd9bebc5bc4 /src | |
parent | 8566487286439e65f217c0e80733d40ea9b19ac8 (diff) |
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 <qt-project.org@the-compiler.org>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qrandom.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
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 <private/qjni_p.h> #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 <assert.h> + 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<uchar *>(buffer) + read, 256); + int ret = getentropy(reinterpret_cast<uchar *>(buffer) + read, 256); + Q_ASSERT(ret == 0); + read += 256; } - getentropy(reinterpret_cast<uchar *>(buffer) + read, count - read); + int ret = getentropy(reinterpret_cast<uchar *>(buffer) + read, count - read); + Q_ASSERT(ret == 0); return count; } }; |