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

Side by Side 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, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/base/mathutils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 405 }
406 } 406 }
407 if (word_to_count == 0) { 407 if (word_to_count == 0) {
408 return bits; 408 return bits;
409 } 409 }
410 410
411 // Public domain bit-twiddling hack from: 411 // Public domain bit-twiddling hack from:
412 // http://graphics.stanford.edu/~seander/bithacks.html 412 // http://graphics.stanford.edu/~seander/bithacks.html
413 // Counts the trailing 0s in the word. 413 // Counts the trailing 0s in the word.
414 unsigned int zeroes = 32; 414 unsigned int zeroes = 32;
415 word_to_count &= -static_cast<int32_t>(word_to_count); 415 // This could also be written word_to_count &= -word_to_count, but
416 // MSVC emits warning C4146 when negating an unsigned number.
417 word_to_count &= ~word_to_count + 1; // Isolate lowest set bit.
416 if (word_to_count) zeroes--; 418 if (word_to_count) zeroes--;
417 if (word_to_count & 0x0000FFFF) zeroes -= 16; 419 if (word_to_count & 0x0000FFFF) zeroes -= 16;
418 if (word_to_count & 0x00FF00FF) zeroes -= 8; 420 if (word_to_count & 0x00FF00FF) zeroes -= 8;
419 if (word_to_count & 0x0F0F0F0F) zeroes -= 4; 421 if (word_to_count & 0x0F0F0F0F) zeroes -= 4;
420 if (word_to_count & 0x33333333) zeroes -= 2; 422 if (word_to_count & 0x33333333) zeroes -= 2;
421 if (word_to_count & 0x55555555) zeroes -= 1; 423 if (word_to_count & 0x55555555) zeroes -= 1;
422 424
423 return bits + (32 - zeroes); 425 return bits + (32 - zeroes);
424 } 426 }
425 427
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 IPAddress GetAnyIP(int family) { 517 IPAddress GetAnyIP(int family) {
516 if (family == AF_INET) { 518 if (family == AF_INET) {
517 return rtc::IPAddress(INADDR_ANY); 519 return rtc::IPAddress(INADDR_ANY);
518 } 520 }
519 if (family == AF_INET6) { 521 if (family == AF_INET6) {
520 return rtc::IPAddress(in6addr_any); 522 return rtc::IPAddress(in6addr_any);
521 } 523 }
522 return rtc::IPAddress(); 524 return rtc::IPAddress();
523 } 525 }
524 526
525 } // Namespace rtc 527 } // namespace rtc
OLDNEW
« 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