Skip to content

Commit 12191bf

Browse files
committed
improve comparisons around unsigned
1 parent 403480e commit 12191bf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

IntelPresentMon/CommonUtilities/win/Event.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Event.h"
22
#include "WinAPI.h"
33
#include <stdexcept>
4+
#include <cassert>
45

56
namespace pmon::util::win
67
{
@@ -39,10 +40,12 @@ namespace pmon::util::win
3940
std::optional<uint32_t> WaitOnMultipleEvents(std::span<Event::HandleType> events, bool waitAll, uint32_t milli)
4041
{
4142
const auto nEvents = (DWORD)events.size();
43+
assert(nEvents <= MAXIMUM_WAIT_OBJECTS);
4244
const auto status = WaitForMultipleObjects(nEvents, events.data(), (BOOL)waitAll, (DWORD)milli);
43-
const DWORD eventIndex = status - WAIT_OBJECT_0;
44-
if (eventIndex >= 0 && eventIndex < nEvents) {
45-
return eventIndex;
45+
if (status >= WAIT_OBJECT_0) {
46+
if (const DWORD eventIndex = status - WAIT_OBJECT_0; eventIndex < nEvents) {
47+
return eventIndex;
48+
}
4649
}
4750
else if (status == WAIT_TIMEOUT) {
4851
return {};

0 commit comments

Comments
 (0)