From 664cdafb8ad7ccef531cb6bf7bd42752841f220f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Susano=20Pinto?= Date: Wed, 20 May 2015 11:11:07 +0200 Subject: [PATCH] Replace assert() with static_assert() if the condition is evaluatable at 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} --- webrtc/modules/audio_processing/audio_processing_impl.cc | 2 +- webrtc/voice_engine/voe_base_impl.cc | 2 +- webrtc/voice_engine/voe_file_impl.cc | 8 ++++---- webrtc/voice_engine/voe_hardware_impl.cc | 8 ++++---- webrtc/voice_engine/voe_rtp_rtcp_impl.cc | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc index e8210c935c..aed63412df 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.cc +++ b/webrtc/modules/audio_processing/audio_processing_impl.cc @@ -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; diff --git a/webrtc/voice_engine/voe_base_impl.cc b/webrtc/voice_engine/voe_base_impl.cc index e245fca110..7bfaddc744 100644 --- a/webrtc/voice_engine/voe_base_impl.cc +++ b/webrtc/voice_engine/voe_base_impl.cc @@ -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); diff --git a/webrtc/voice_engine/voe_file_impl.cc b/webrtc/voice_engine/voe_file_impl.cc index ccf4ec077f..78613b03f5 100644 --- a/webrtc/voice_engine/voe_file_impl.cc +++ b/webrtc/voice_engine/voe_file_impl.cc @@ -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; @@ -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; @@ -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); @@ -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); diff --git a/webrtc/voice_engine/voe_hardware_impl.cc b/webrtc/voice_engine/voe_hardware_impl.cc index 8e9485cb2a..bac08724c5 100644 --- a/webrtc/voice_engine/voe_hardware_impl.cc +++ b/webrtc/voice_engine/voe_hardware_impl.cc @@ -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]; @@ -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]; diff --git a/webrtc/voice_engine/voe_rtp_rtcp_impl.cc b/webrtc/voice_engine/voe_rtp_rtcp_impl.cc index 71f3c849f2..fa15bc895b 100644 --- a/webrtc/voice_engine/voe_rtp_rtcp_impl.cc +++ b/webrtc/voice_engine/voe_rtp_rtcp_impl.cc @@ -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;