[tor-commits] [tor/maint-0.3.1] Fix the clz32 and clz64 settings on MSVC.

nickm at torproject.org nickm at torproject.org
Wed Jan 3 14:00:05 UTC 2018


commit accd0ea65bb817ad8f2361c5ca06c40ac9a9a11f
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Dec 20 09:34:25 2017 -0500

    Fix the clz32 and clz64 settings on MSVC.
    
    Fixes bug 24633; bugfix on 0.2.9.1-alpha.
---
 changes/bug24633                  | 5 +++++
 src/ext/timeouts/timeout-bitops.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/changes/bug24633 b/changes/bug24633
new file mode 100644
index 000000000..028c7cc14
--- /dev/null
+++ b/changes/bug24633
@@ -0,0 +1,5 @@
+  o Minor bugfixes (portability, msvc):
+    - Fix a bug in the bit-counting parts of our timing-wheel code on
+      MSVC. (Note that MSVC is still not a supported build platform,
+      due to cyptographic timing channel risks.) Fixes bug 24633;
+      bugfix on 0.2.9.1-alpha.
diff --git a/src/ext/timeouts/timeout-bitops.c b/src/ext/timeouts/timeout-bitops.c
index a018f33b9..45466f6cb 100644
--- a/src/ext/timeouts/timeout-bitops.c
+++ b/src/ext/timeouts/timeout-bitops.c
@@ -40,7 +40,7 @@ static __inline int clz32(unsigned long val)
 {
 	DWORD zeros = 0;
 	_BitScanReverse(&zeros, val);
-	return zeros;
+	return 31 - zeros;
 }
 #ifdef _WIN64
 /* According to the documentation, these only exist on Win64. */
@@ -54,7 +54,7 @@ static __inline int clz64(uint64_t val)
 {
 	DWORD zeros = 0;
 	_BitScanReverse64(&zeros, val);
-	return zeros;
+	return 63 - zeros;
 }
 #else
 static __inline int ctz64(uint64_t val)





More information about the tor-commits mailing list