Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: webrtc/base/ipaddress.cc

Issue 1744183002: Fix some signed overflow errors causing undefined behavior (in theory). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Format and comment Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/mathutils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/ipaddress.cc
diff --git a/webrtc/base/ipaddress.cc b/webrtc/base/ipaddress.cc
index c92f33c74d8baaa9b947da93e7fa1e7099d17982..b1d1265ae479ee4c97f106d2a52fabb0614ca897 100644
--- a/webrtc/base/ipaddress.cc
+++ b/webrtc/base/ipaddress.cc
@@ -412,7 +412,9 @@ int CountIPMaskBits(IPAddress mask) {
// http://graphics.stanford.edu/~seander/bithacks.html
// Counts the trailing 0s in the word.
unsigned int zeroes = 32;
- word_to_count &= -static_cast<int32_t>(word_to_count);
+ // This could also be written word_to_count &= -word_to_count, but
+ // MSVC emits warning C4146 when negating an unsigned number.
+ word_to_count &= ~word_to_count + 1; // Isolate lowest set bit.
if (word_to_count) zeroes--;
if (word_to_count & 0x0000FFFF) zeroes -= 16;
if (word_to_count & 0x00FF00FF) zeroes -= 8;
@@ -522,4 +524,4 @@ IPAddress GetAnyIP(int family) {
return rtc::IPAddress();
}
-} // Namespace rtc
+} // namespace rtc
« no previous file with comments | « no previous file | webrtc/base/mathutils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698