Skip to content

Commit

Permalink
Fix C4005 and C4267 MSVC warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jul 21, 2023
1 parent 98c64b5 commit 1c68202
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
*/

#if defined(_WIN32)
/*
* The defined WIN32_NO_STATUS macro disables return code definitions in
* windows.h, which avoids "macro redefinition" MSVC warnings in ntstatus.h.
*/
#define WIN32_NO_STATUS
#include <windows.h>
#undef WIN32_NO_STATUS
#include <ntstatus.h>
#include <bcrypt.h>
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
Expand All @@ -36,7 +42,7 @@
/* Returns 1 on success, and 0 on failure. */
static int fill_random(unsigned char* data, size_t size) {
#if defined(_WIN32)
NTSTATUS res = BCryptGenRandom(NULL, data, size, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
NTSTATUS res = BCryptGenRandom(NULL, data, (ULONG)size, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
if (res != STATUS_SUCCESS || size > ULONG_MAX) {
return 0;
} else {
Expand Down

0 comments on commit 1c68202

Please sign in to comment.