Skip to content

Commit

Permalink
Replace assert() with static_assert() if the condition is evaluatable at
Browse files Browse the repository at this point in the history
compile time.

The condition of static_assert() is evaluated at compile time which is safer and
more efficient.

Note that static_assert() requires C++11.

The changes were generated by the misc-static-assert ClangTidy check by alexfh@google.com

R=tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/51019004

Cr-Commit-Position: refs/heads/master@{#9231}
  • Loading branch information
andresusanopinto committed May 20, 2015
1 parent 5ca688b commit 664cdaf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion webrtc/modules/audio_processing/audio_processing_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ int AudioProcessingImpl::delay_offset_ms() const {
int AudioProcessingImpl::StartDebugRecording(
const char filename[AudioProcessing::kMaxFilenameSize]) {
CriticalSectionScoped crit_scoped(crit_);
assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize);
static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, "");

if (filename == NULL) {
return kNullPointerError;
Expand Down
2 changes: 1 addition & 1 deletion webrtc/voice_engine/voe_base_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ int VoEBaseImpl::StopSend(int channel) {
}

int VoEBaseImpl::GetVersion(char version[1024]) {
assert(kVoiceEngineVersionMaxMessageSize == 1024);
static_assert(kVoiceEngineVersionMaxMessageSize == 1024, "");

if (version == nullptr) {
shared_->SetLastError(VE_INVALID_ARGUMENT, kTraceError);
Expand Down
8 changes: 4 additions & 4 deletions webrtc/voice_engine/voe_file_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int VoEFileImpl::StartPlayingFileLocally(int channel,
" stopPointMs=%d)",
channel, fileNameUTF8, loop, format, volumeScaling, startPointMs,
stopPointMs);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
Expand Down Expand Up @@ -152,7 +152,7 @@ int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
"volumeScaling=%5.3f)",
channel, fileNameUTF8, loop, mixWithMicrophone, format,
volumeScaling);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
Expand Down Expand Up @@ -310,7 +310,7 @@ int VoEFileImpl::StartRecordingPlayout(int channel,
"StartRecordingPlayout(channel=%d, fileNameUTF8=%s, "
"compression, maxSizeBytes=%d)",
channel, fileNameUTF8, maxSizeBytes);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");

if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
Expand Down Expand Up @@ -384,7 +384,7 @@ int VoEFileImpl::StartRecordingMicrophone(const char* fileNameUTF8,
"StartRecordingMicrophone(fileNameUTF8=%s, compression, "
"maxSizeBytes=%d)",
fileNameUTF8, maxSizeBytes);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");

if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
Expand Down
8 changes: 4 additions & 4 deletions webrtc/voice_engine/voe_hardware_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ int VoEHardwareImpl::GetRecordingDeviceName(int index,
const uint16_t strLen = 128;

// Check if length has been changed in module
assert(strLen == kAdmMaxDeviceNameSize);
assert(strLen == kAdmMaxGuidSize);
static_assert(strLen == kAdmMaxDeviceNameSize, "");
static_assert(strLen == kAdmMaxGuidSize, "");

char name[strLen];
char guid[strLen];
Expand Down Expand Up @@ -235,8 +235,8 @@ int VoEHardwareImpl::GetPlayoutDeviceName(int index,
const uint16_t strLen = 128;

// Check if length has been changed in module
assert(strLen == kAdmMaxDeviceNameSize);
assert(strLen == kAdmMaxGuidSize);
static_assert(strLen == kAdmMaxDeviceNameSize, "");
static_assert(strLen == kAdmMaxGuidSize, "");

char name[strLen];
char guid[strLen];
Expand Down
2 changes: 1 addition & 1 deletion webrtc/voice_engine/voe_rtp_rtcp_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ int VoERTP_RTCPImpl::StartRTPDump(int channel,
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"StartRTPDump(channel=%d, fileNameUTF8=%s, direction=%d)",
channel, fileNameUTF8, direction);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
Expand Down

0 comments on commit 664cdaf

Please sign in to comment.