webrtc/base: Use RTC_DCHECK() instead of assert()
Review-Url: https://codereview.webrtc.org/2325623002
Cr-Commit-Position: refs/heads/master@{#14192}
diff --git a/webrtc/base/bytebuffer.cc b/webrtc/base/bytebuffer.cc
index 9730ff2..c2ffe60 100644
--- a/webrtc/base/bytebuffer.cc
+++ b/webrtc/base/bytebuffer.cc
@@ -10,7 +10,6 @@
#include "webrtc/base/bytebuffer.h"
-#include <assert.h>
#include <string.h>
#include <algorithm>
diff --git a/webrtc/base/fileutils.cc b/webrtc/base/fileutils.cc
index d354dd8..ae9309c 100644
--- a/webrtc/base/fileutils.cc
+++ b/webrtc/base/fileutils.cc
@@ -8,11 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include <assert.h>
+#include "webrtc/base/fileutils.h"
#include "webrtc/base/arraysize.h"
+#include "webrtc/base/checks.h"
#include "webrtc/base/pathutils.h"
-#include "webrtc/base/fileutils.h"
#include "webrtc/base/stringutils.h"
#include "webrtc/base/stream.h"
@@ -112,7 +112,7 @@
#if defined(WEBRTC_WIN)
return ToUtf8(data_.cFileName);
#else
- assert(dirent_ != NULL);
+ RTC_DCHECK(dirent_);
return dirent_->d_name;
#endif
}
diff --git a/webrtc/base/firewallsocketserver.cc b/webrtc/base/firewallsocketserver.cc
index bf3ec42..d6d03df 100644
--- a/webrtc/base/firewallsocketserver.cc
+++ b/webrtc/base/firewallsocketserver.cc
@@ -10,11 +10,10 @@
#include "webrtc/base/firewallsocketserver.h"
-#include <assert.h>
-
#include <algorithm>
#include "webrtc/base/asyncsocket.h"
+#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
namespace rtc {
@@ -220,7 +219,7 @@
}
FirewallManager::~FirewallManager() {
- assert(servers_.empty());
+ RTC_DCHECK(servers_.empty());
}
void FirewallManager::AddServer(FirewallSocketServer* server) {
diff --git a/webrtc/base/flags.cc b/webrtc/base/flags.cc
index 248c5c3..a138b8f 100644
--- a/webrtc/base/flags.cc
+++ b/webrtc/base/flags.cc
@@ -8,18 +8,19 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include "webrtc/base/flags.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "webrtc/base/checks.h"
#if defined(WEBRTC_WIN)
#include "webrtc/base/win32.h"
#include <shellapi.h>
#endif
-#include "webrtc/base/flags.h"
-
namespace rtc {
// -----------------------------------------------------------------------------
// Implementation of Flag
@@ -256,7 +257,8 @@
}
void FlagList::Register(Flag* flag) {
- assert(flag != NULL && strlen(flag->name()) > 0);
+ RTC_DCHECK(flag);
+ RTC_DCHECK_GT(strlen(flag->name()), 0u);
// NOTE: Don't call Lookup() within Register because it accesses the name_
// of other flags in list_, and if the flags are coming from two different
// compilation units, the initialization order between them is undefined, and
diff --git a/webrtc/base/flags.h b/webrtc/base/flags.h
index d16f12b..6ca50b5 100644
--- a/webrtc/base/flags.h
+++ b/webrtc/base/flags.h
@@ -23,8 +23,6 @@
#ifndef WEBRTC_BASE_FLAGS_H__
#define WEBRTC_BASE_FLAGS_H__
-#include <assert.h>
-
#include "webrtc/base/checks.h"
#include "webrtc/base/common.h"
#include "webrtc/base/constructormagic.h"
@@ -88,43 +86,43 @@
// Flag variables
bool* bool_variable() const {
- assert(type_ == BOOL);
+ RTC_DCHECK_EQ(BOOL, type_);
return &variable_->b;
}
int* int_variable() const {
- assert(type_ == INT);
+ RTC_DCHECK_EQ(INT, type_);
return &variable_->i;
}
double* float_variable() const {
- assert(type_ == FLOAT);
+ RTC_DCHECK_EQ(FLOAT, type_);
return &variable_->f;
}
const char** string_variable() const {
- assert(type_ == STRING);
+ RTC_DCHECK_EQ(STRING, type_);
return &variable_->s;
}
// Default values
bool bool_default() const {
- assert(type_ == BOOL);
+ RTC_DCHECK_EQ(BOOL, type_);
return default_.b;
}
int int_default() const {
- assert(type_ == INT);
+ RTC_DCHECK_EQ(INT, type_);
return default_.i;
}
double float_default() const {
- assert(type_ == FLOAT);
+ RTC_DCHECK_EQ(FLOAT, type_);
return default_.f;
}
const char* string_default() const {
- assert(type_ == STRING);
+ RTC_DCHECK_EQ(STRING, type_);
return default_.s;
}
diff --git a/webrtc/base/maccocoasocketserver.mm b/webrtc/base/maccocoasocketserver.mm
index 123ffdc..034737e 100644
--- a/webrtc/base/maccocoasocketserver.mm
+++ b/webrtc/base/maccocoasocketserver.mm
@@ -11,7 +11,6 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
-#include <assert.h>
#include "webrtc/base/scoped_autorelease_pool.h"
diff --git a/webrtc/base/maccocoathreadhelper.mm b/webrtc/base/maccocoathreadhelper.mm
index 59ae6c4..70d920d 100644
--- a/webrtc/base/maccocoathreadhelper.mm
+++ b/webrtc/base/maccocoathreadhelper.mm
@@ -9,11 +9,12 @@
*/
// Helper function for using Cocoa with Posix threading.
-#import <assert.h>
#import <Foundation/Foundation.h>
#import "webrtc/base/maccocoathreadhelper.h"
+#include "webrtc/base/checks.h"
+
namespace rtc {
// Cocoa must be "put into multithreading mode" before Cocoa functionality can
@@ -34,7 +35,7 @@
[hack drain];
}
- assert([NSThread isMultiThreaded]);
+ RTC_DCHECK([NSThread isMultiThreaded]);
}
} // namespace rtc
diff --git a/webrtc/base/nattypes.cc b/webrtc/base/nattypes.cc
index 890a664..1e37698 100644
--- a/webrtc/base/nattypes.cc
+++ b/webrtc/base/nattypes.cc
@@ -8,10 +8,10 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include <assert.h>
-
#include "webrtc/base/nattypes.h"
+#include "webrtc/base/checks.h"
+
namespace rtc {
class SymmetricNAT : public NAT {
@@ -44,11 +44,17 @@
NAT* NAT::Create(NATType type) {
switch (type) {
- case NAT_OPEN_CONE: return new OpenConeNAT();
- case NAT_ADDR_RESTRICTED: return new AddressRestrictedNAT();
- case NAT_PORT_RESTRICTED: return new PortRestrictedNAT();
- case NAT_SYMMETRIC: return new SymmetricNAT();
- default: assert(0); return 0;
+ case NAT_OPEN_CONE:
+ return new OpenConeNAT();
+ case NAT_ADDR_RESTRICTED:
+ return new AddressRestrictedNAT();
+ case NAT_PORT_RESTRICTED:
+ return new PortRestrictedNAT();
+ case NAT_SYMMETRIC:
+ return new SymmetricNAT();
+ default:
+ RTC_NOTREACHED();
+ return 0;
}
}
diff --git a/webrtc/base/physicalsocketserver.cc b/webrtc/base/physicalsocketserver.cc
index c94b9a3..f0dc69f 100644
--- a/webrtc/base/physicalsocketserver.cc
+++ b/webrtc/base/physicalsocketserver.cc
@@ -13,8 +13,6 @@
#pragma warning(disable:4786)
#endif
-#include <assert.h>
-
#ifdef MEMORY_SANITIZER
#include <sanitizer/msan_interface.h>
#endif
diff --git a/webrtc/base/sec_buffer.h b/webrtc/base/sec_buffer.h
index e6ffea4..3ef720a 100644
--- a/webrtc/base/sec_buffer.h
+++ b/webrtc/base/sec_buffer.h
@@ -73,16 +73,9 @@
Clear();
}
- private:
- // A placeholder function for compile-time asserts on the class
- void CompileAsserts() {
- // never invoked...
- assert(false); // _T("Notreached")
-
- // This class must not extend the size of SecBuffer, since
- // we use arrays of CSecBuffer in CSecBufferBundle below
- cassert(sizeof(CSecBuffer<SSPIFree> == sizeof(SecBuffer)));
- }
+ // This class must not extend the size of SecBuffer, since we use arrays of
+ // CSecBuffer in CSecBufferBundle below.
+ static_assert(sizeof(CSecBuffer<pfnFreeBuffer>) == sizeof(SecBuffer), "");
};
// Contains all generic implementation for the
diff --git a/webrtc/base/virtualsocketserver.h b/webrtc/base/virtualsocketserver.h
index 565222b..cce0279 100644
--- a/webrtc/base/virtualsocketserver.h
+++ b/webrtc/base/virtualsocketserver.h
@@ -11,11 +11,10 @@
#ifndef WEBRTC_BASE_VIRTUALSOCKETSERVER_H_
#define WEBRTC_BASE_VIRTUALSOCKETSERVER_H_
-#include <assert.h>
-
#include <deque>
#include <map>
+#include "webrtc/base/checks.h"
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/messagequeue.h"
#include "webrtc/base/socketserver.h"
@@ -86,7 +85,8 @@
// is separate from calculations to drop based on queue size.
double drop_probability() { return drop_prob_; }
void set_drop_probability(double drop_prob) {
- assert((0 <= drop_prob) && (drop_prob <= 1));
+ RTC_DCHECK_GE(drop_prob, 0.0);
+ RTC_DCHECK_LE(drop_prob, 1.0);
drop_prob_ = drop_prob;
}
diff --git a/webrtc/base/winping.cc b/webrtc/base/winping.cc
index be436c3..1b0fa5d 100644
--- a/webrtc/base/winping.cc
+++ b/webrtc/base/winping.cc
@@ -10,12 +10,12 @@
#include "webrtc/base/winping.h"
-#include <assert.h>
#include <Iphlpapi.h>
#include <algorithm>
#include "webrtc/base/byteorder.h"
+#include "webrtc/base/checks.h"
#include "webrtc/base/common.h"
#include "webrtc/base/ipaddress.h"
#include "webrtc/base/logging.h"
@@ -218,7 +218,7 @@
return PING_INVALID_PARAMS;
}
- assert(IsValid());
+ RTC_DCHECK(IsValid());
IP_OPTION_INFORMATION ipopt;
memset(&ipopt, 0, sizeof(ipopt));