From caeb3c4a6f16699c1061ba36b605610deae2038d Mon Sep 17 00:00:00 2001
From: Iain Patterson <me@iain.cx>
Date: Tue, 16 May 2017 08:18:29 +0100
Subject: [PATCH] Fix lockup on with 64 cores.

Thanks foi.
---
 README.txt | 1 +
 nssm.cpp   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/README.txt b/README.txt
index eaecac2..92fe74f 100644
--- a/README.txt
+++ b/README.txt
@@ -1044,6 +1044,7 @@ Thanks to Meang Akira Tanaka for suggestion and initial implementation of
 the statuscode command.
 Thanks to Kirill Kovalenko for reporting a crash with NANO server.
 Thanks to Connor Reynolds for spotting a potential buffer overflow.
+Thanks to foi for spotting a hang with 64 cores.
 
 Licence
 -------
diff --git a/nssm.cpp b/nssm.cpp
index 69abbfb..9c51c53 100644
--- a/nssm.cpp
+++ b/nssm.cpp
@@ -223,7 +223,7 @@ static int elevate(int argc, TCHAR **argv, unsigned long message) {
 int num_cpus() {
   DWORD_PTR i, affinity, system_affinity;
   if (! GetProcessAffinityMask(GetCurrentProcess(), &affinity, &system_affinity)) return 64;
-  for (i = 0; system_affinity & (1LL << i); i++);
+  for (i = 0; system_affinity & (1LL << i); i++) if (i == 64) break;
   return (int) i;
 }
 
-- 
2.7.4