From ee89e7870c332c943fb78faebc63e47d0a314d74 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Wed, 9 Aug 2017 17:22:01 -0700 Subject: [PATCH] Replace CHECK(x && y) with two separate CHECK() calls That way, the debug printout will tell us which of x and y that was false. BUG=none Review-Url: https://codereview.webrtc.org/2988153003 Cr-Commit-Position: refs/heads/master@{#19297} --- .../logging/rtc_event_log/rtc_event_log2stats.cc | 3 ++- .../logging/rtc_event_log/rtc_event_log_parser.cc | 3 ++- .../modules/audio_coding/codecs/cng/webrtc_cng.cc | 6 ++++-- .../codecs/opus/audio_encoder_opus.cc | 3 ++- .../dummy/file_audio_device_factory.cc | 4 ++-- .../dummy/file_audio_device_factory.h | 2 +- .../audio_processing/transient/moving_moments.cc | 5 ++++- .../desktop_capturer_differ_wrapper.cc | 3 ++- .../desktop_capture/desktop_frame_generator.cc | 4 ++-- .../win/dxgi_adapter_duplicator.cc | 15 +++++++++------ .../desktop_capture/win/dxgi_output_duplicator.cc | 6 ++++-- .../modules/desktop_capture/win/dxgi_texture.cc | 3 ++- .../desktop_capture/win/dxgi_texture_mapping.cc | 3 ++- .../desktop_capture/win/dxgi_texture_staging.cc | 3 ++- webrtc/modules/rtp_rtcp/source/rtp_sender.cc | 5 ++--- webrtc/modules/video_coding/frame_object.cc | 3 ++- webrtc/p2p/base/p2ptransportchannel_unittest.cc | 3 ++- webrtc/p2p/client/basicportallocator.cc | 3 ++- webrtc/pc/datachannel.cc | 11 +++++++---- webrtc/pc/remoteaudiosource.cc | 3 ++- webrtc/pc/rtpreceiver.cc | 3 ++- webrtc/pc/rtpsender.cc | 6 ++++-- webrtc/pc/test/fakedatachannelprovider.h | 3 ++- webrtc/pc/test/fakertccertificategenerator.h | 8 ++++---- webrtc/rtc_base/macutils.cc | 4 +++- webrtc/rtc_base/opensslstreamadapter.cc | 6 ++++-- webrtc/rtc_base/proxyserver.cc | 6 ++++-- webrtc/rtc_base/socketaddress.cc | 4 ++-- webrtc/voice_engine/channel.cc | 6 ++++-- 29 files changed, 86 insertions(+), 51 deletions(-) diff --git a/webrtc/logging/rtc_event_log/rtc_event_log2stats.cc b/webrtc/logging/rtc_event_log/rtc_event_log2stats.cc index eb290b8845..6b21cf1a7e 100644 --- a/webrtc/logging/rtc_event_log/rtc_event_log2stats.cc +++ b/webrtc/logging/rtc_event_log/rtc_event_log2stats.cc @@ -54,7 +54,8 @@ std::pair ParseVarInt(std::istream& stream) { if (stream.eof()) { return std::make_pair(varint, false); } - RTC_DCHECK(0 <= byte && byte <= 255); + RTC_DCHECK_GE(byte, 0); + RTC_DCHECK_LE(byte, 255); varint |= static_cast(byte & 0x7F) << (7 * bytes_read); if ((byte & 0x80) == 0) { return std::make_pair(varint, true); diff --git a/webrtc/logging/rtc_event_log/rtc_event_log_parser.cc b/webrtc/logging/rtc_event_log/rtc_event_log_parser.cc index 8a8d8e3d47..a7237ee851 100644 --- a/webrtc/logging/rtc_event_log/rtc_event_log_parser.cc +++ b/webrtc/logging/rtc_event_log/rtc_event_log_parser.cc @@ -104,7 +104,8 @@ std::pair ParseVarInt(std::istream& stream) { if (stream.eof()) { return std::make_pair(varint, false); } - RTC_DCHECK(0 <= byte && byte <= 255); + RTC_DCHECK_GE(byte, 0); + RTC_DCHECK_LE(byte, 255); varint |= static_cast(byte & 0x7F) << (7 * bytes_read); if ((byte & 0x80) == 0) { return std::make_pair(varint, true); diff --git a/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.cc b/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.cc index 9461cd00b9..b891d8423d 100644 --- a/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.cc +++ b/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.cc @@ -218,13 +218,15 @@ ComfortNoiseEncoder::ComfortNoiseEncoder(int fs, int interval, int quality) enc_reflCoefs_{0}, enc_corrVector_{0}, enc_seed_(7777) /* For debugging only. */ { - RTC_CHECK(quality <= WEBRTC_CNG_MAX_LPC_ORDER && quality > 0); + RTC_CHECK_GT(quality, 0); + RTC_CHECK_LE(quality, WEBRTC_CNG_MAX_LPC_ORDER); /* Needed to get the right function pointers in SPLIB. */ WebRtcSpl_Init(); } void ComfortNoiseEncoder::Reset(int fs, int interval, int quality) { - RTC_CHECK(quality <= WEBRTC_CNG_MAX_LPC_ORDER && quality > 0); + RTC_CHECK_GT(quality, 0); + RTC_CHECK_LE(quality, WEBRTC_CNG_MAX_LPC_ORDER); enc_nrOfCoefs_ = quality; enc_sampfreq_ = fs; enc_interval_ = interval; diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc index 5b9a895332..e94ea6572e 100644 --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc @@ -391,7 +391,8 @@ AudioEncoderOpus::AudioEncoderOpus( ? std::move(bitrate_smoother) : std::unique_ptr( // We choose 5sec as initial time constant due to empirical data. new SmoothingFilterImpl(5000))) { - RTC_DCHECK(0 <= payload_type && payload_type <= 127); + RTC_DCHECK_GE(payload_type, 0); + RTC_DCHECK_LE(payload_type, 127); // Sanity check of the redundant payload type field that we want to get rid // of. See https://bugs.chromium.org/p/webrtc/issues/detail?id=7847 diff --git a/webrtc/modules/audio_device/dummy/file_audio_device_factory.cc b/webrtc/modules/audio_device/dummy/file_audio_device_factory.cc index bce6be4633..9aeba205d9 100644 --- a/webrtc/modules/audio_device/dummy/file_audio_device_factory.cc +++ b/webrtc/modules/audio_device/dummy/file_audio_device_factory.cc @@ -39,8 +39,8 @@ FileAudioDevice* FileAudioDeviceFactory::CreateFileAudioDevice( void FileAudioDeviceFactory::SetFilenamesToUse( const char* inputAudioFilename, const char* outputAudioFilename) { #ifdef WEBRTC_DUMMY_FILE_DEVICES - RTC_DCHECK(strlen(inputAudioFilename) < MAX_FILENAME_LEN && - strlen(outputAudioFilename) < MAX_FILENAME_LEN); + RTC_DCHECK_LT(strlen(inputAudioFilename), MAX_FILENAME_LEN); + RTC_DCHECK_LT(strlen(outputAudioFilename), MAX_FILENAME_LEN); // Copy the strings since we don't know the lifetime of the input pointers. strncpy(_inputAudioFilename, inputAudioFilename, MAX_FILENAME_LEN); diff --git a/webrtc/modules/audio_device/dummy/file_audio_device_factory.h b/webrtc/modules/audio_device/dummy/file_audio_device_factory.h index 250b7f63a8..6763e02518 100644 --- a/webrtc/modules/audio_device/dummy/file_audio_device_factory.h +++ b/webrtc/modules/audio_device/dummy/file_audio_device_factory.h @@ -31,7 +31,7 @@ class FileAudioDeviceFactory { const char* outputAudioFilename); private: - static const uint32_t MAX_FILENAME_LEN = 512; + enum : uint32_t { MAX_FILENAME_LEN = 512 }; static bool _isConfigured; static char _inputAudioFilename[MAX_FILENAME_LEN]; static char _outputAudioFilename[MAX_FILENAME_LEN]; diff --git a/webrtc/modules/audio_processing/transient/moving_moments.cc b/webrtc/modules/audio_processing/transient/moving_moments.cc index 5701a00270..bca987feb7 100644 --- a/webrtc/modules/audio_processing/transient/moving_moments.cc +++ b/webrtc/modules/audio_processing/transient/moving_moments.cc @@ -32,7 +32,10 @@ MovingMoments::~MovingMoments() {} void MovingMoments::CalculateMoments(const float* in, size_t in_length, float* first, float* second) { - RTC_DCHECK(in && in_length > 0 && first && second); + RTC_DCHECK(in); + RTC_DCHECK_GT(in_length, 0); + RTC_DCHECK(first); + RTC_DCHECK(second); for (size_t i = 0; i < in_length; ++i) { const float old_value = queue_.front(); diff --git a/webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper.cc b/webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper.cc index 9dbcd68e5b..f3a846c765 100644 --- a/webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper.cc +++ b/webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper.cc @@ -61,7 +61,8 @@ void CompareRow(const uint8_t* old_buffer, const int height = bottom - top; const int block_count = (width - 1) / kBlockSize; const int last_block_width = width - block_count * kBlockSize; - RTC_DCHECK(last_block_width <= kBlockSize && last_block_width > 0); + RTC_DCHECK_GT(last_block_width, 0); + RTC_DCHECK_LE(last_block_width, kBlockSize); // The first block-column in a continuous dirty area in current block-row. int first_dirty_x_block = -1; diff --git a/webrtc/modules/desktop_capture/desktop_frame_generator.cc b/webrtc/modules/desktop_capture/desktop_frame_generator.cc index 30a08f2708..7bb58974ff 100644 --- a/webrtc/modules/desktop_capture/desktop_frame_generator.cc +++ b/webrtc/modules/desktop_capture/desktop_frame_generator.cc @@ -64,8 +64,8 @@ void SetUpdatedRegion(DesktopFrame* frame, void PaintRect(DesktopFrame* frame, DesktopRect rect, RgbaColor rgba_color) { static_assert(DesktopFrame::kBytesPerPixel == sizeof(uint32_t), "kBytesPerPixel should be 4."); - RTC_DCHECK(frame->size().width() >= rect.right() && - frame->size().height() >= rect.bottom()); + RTC_DCHECK_GE(frame->size().width(), rect.right()); + RTC_DCHECK_GE(frame->size().height(), rect.bottom()); uint32_t color = rgba_color.ToUInt32(); uint8_t* row = frame->GetFrameDataAtPos(rect.top_left()); for (int i = 0; i < rect.height(); i++) { diff --git a/webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc b/webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc index c2a0794fe3..4174dc952c 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc @@ -134,20 +134,22 @@ bool DxgiAdapterDuplicator::Duplicate(Context* context, bool DxgiAdapterDuplicator::DuplicateMonitor(Context* context, int monitor_id, SharedDesktopFrame* target) { - RTC_DCHECK(monitor_id >= 0 && - monitor_id < static_cast(duplicators_.size()) && - context->contexts.size() == duplicators_.size()); + RTC_DCHECK_GE(monitor_id, 0); + RTC_DCHECK_LT(monitor_id, duplicators_.size()); + RTC_DCHECK_EQ(context->contexts.size(), duplicators_.size()); return duplicators_[monitor_id].Duplicate(&context->contexts[monitor_id], DesktopVector(), target); } DesktopRect DxgiAdapterDuplicator::ScreenRect(int id) const { - RTC_DCHECK(id >= 0 && id < static_cast(duplicators_.size())); + RTC_DCHECK_GE(id, 0); + RTC_DCHECK_LT(id, duplicators_.size()); return duplicators_[id].desktop_rect(); } const std::string& DxgiAdapterDuplicator::GetDeviceName(int id) const { - RTC_DCHECK(id >= 0 && id < static_cast(duplicators_.size())); + RTC_DCHECK_GE(id, 0); + RTC_DCHECK_LT(id, duplicators_.size()); return duplicators_[id].device_name(); } @@ -166,7 +168,8 @@ int64_t DxgiAdapterDuplicator::GetNumFramesCaptured() const { void DxgiAdapterDuplicator::TranslateRect(const DesktopVector& position) { desktop_rect_.Translate(position); - RTC_DCHECK(desktop_rect_.left() >= 0 && desktop_rect_.top() >= 0); + RTC_DCHECK_GE(desktop_rect_.left(), 0); + RTC_DCHECK_GE(desktop_rect_.top(), 0); for (auto& duplicator : duplicators_) { duplicator.TranslateRect(position); } diff --git a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc index 21453b28ef..acb9c9df0f 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc @@ -69,7 +69,8 @@ DxgiOutputDuplicator::DxgiOutputDuplicator(const D3dDevice& device, desktop_rect_(RECTToDesktopRect(desc.DesktopCoordinates)) { RTC_DCHECK(output_); RTC_DCHECK(!desktop_rect_.is_empty()); - RTC_DCHECK(desktop_rect_.width() > 0 && desktop_rect_.height() > 0); + RTC_DCHECK_GT(desktop_rect_.width(), 0); + RTC_DCHECK_GT(desktop_rect_.height(), 0); } DxgiOutputDuplicator::DxgiOutputDuplicator(DxgiOutputDuplicator&& other) = @@ -385,7 +386,8 @@ int64_t DxgiOutputDuplicator::num_frames_captured() const { void DxgiOutputDuplicator::TranslateRect(const DesktopVector& position) { desktop_rect_.Translate(position); - RTC_DCHECK(desktop_rect_.left() >= 0 && desktop_rect_.top() >= 0); + RTC_DCHECK_GE(desktop_rect_.left(), 0); + RTC_DCHECK_GE(desktop_rect_.top(), 0); } } // namespace webrtc diff --git a/webrtc/modules/desktop_capture/win/dxgi_texture.cc b/webrtc/modules/desktop_capture/win/dxgi_texture.cc index 964e00f9c7..f9cfd82ea1 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_texture.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_texture.cc @@ -42,7 +42,8 @@ DxgiTexture::~DxgiTexture() = default; bool DxgiTexture::CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info, IDXGIResource* resource) { - RTC_DCHECK(resource && frame_info.AccumulatedFrames > 0); + RTC_DCHECK_GT(frame_info.AccumulatedFrames, 0); + RTC_DCHECK(resource); ComPtr texture; _com_error error = resource->QueryInterface( __uuidof(ID3D11Texture2D), diff --git a/webrtc/modules/desktop_capture/win/dxgi_texture_mapping.cc b/webrtc/modules/desktop_capture/win/dxgi_texture_mapping.cc index 90d8e896f1..66e5e75812 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_texture_mapping.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_texture_mapping.cc @@ -29,7 +29,8 @@ DxgiTextureMapping::~DxgiTextureMapping() = default; bool DxgiTextureMapping::CopyFromTexture( const DXGI_OUTDUPL_FRAME_INFO& frame_info, ID3D11Texture2D* texture) { - RTC_DCHECK(texture && frame_info.AccumulatedFrames > 0); + RTC_DCHECK_GT(frame_info.AccumulatedFrames, 0); + RTC_DCHECK(texture); *rect() = {0}; _com_error error = duplication_->MapDesktopSurface(rect()); if (error.Error() != S_OK) { diff --git a/webrtc/modules/desktop_capture/win/dxgi_texture_staging.cc b/webrtc/modules/desktop_capture/win/dxgi_texture_staging.cc index 48dc02748b..c4415ca795 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_texture_staging.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_texture_staging.cc @@ -87,7 +87,8 @@ void DxgiTextureStaging::AssertStageAndSurfaceAreSameObject() { bool DxgiTextureStaging::CopyFromTexture( const DXGI_OUTDUPL_FRAME_INFO& frame_info, ID3D11Texture2D* texture) { - RTC_DCHECK(texture && frame_info.AccumulatedFrames > 0); + RTC_DCHECK_GT(frame_info.AccumulatedFrames, 0); + RTC_DCHECK(texture); // AcquireNextFrame returns a CPU inaccessible IDXGIResource, so we need to // copy it to a CPU accessible staging ID3D11Texture2D. diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index 024e028393..89e7735c7a 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -288,9 +288,8 @@ void RTPSender::SetSendPayloadType(int8_t payload_type) { } void RTPSender::SetMaxRtpPacketSize(size_t max_packet_size) { - // Sanity check. - RTC_DCHECK(max_packet_size >= 100 && max_packet_size <= IP_PACKET_SIZE) - << "Invalid max payload length: " << max_packet_size; + RTC_DCHECK_GE(max_packet_size, 100); + RTC_DCHECK_LE(max_packet_size, IP_PACKET_SIZE); rtc::CritScope lock(&send_critsect_); max_packet_size_ = max_packet_size; } diff --git a/webrtc/modules/video_coding/frame_object.cc b/webrtc/modules/video_coding/frame_object.cc index 25d0e29d21..1d858fcc0e 100644 --- a/webrtc/modules/video_coding/frame_object.cc +++ b/webrtc/modules/video_coding/frame_object.cc @@ -102,7 +102,8 @@ RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer, timestamp = first_packet->timestamp; VCMPacket* last_packet = packet_buffer_->GetPacket(last_seq_num); - RTC_CHECK(last_packet && last_packet->markerBit); + RTC_CHECK(last_packet); + RTC_CHECK(last_packet->markerBit); // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ // ts_126114v120700p.pdf Section 7.4.5. // The MTSI client shall add the payload bytes as defined in this clause diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc index 3ba2558809..62fddb2b58 100644 --- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc +++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc @@ -2179,7 +2179,8 @@ TEST_F(P2PTransportChannelTest, SignalReadyToSendWithPresumedWritable) { class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { protected: void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { - RTC_CHECK(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); + RTC_CHECK_GE(nat_type, NAT_FULL_CONE); + RTC_CHECK_LE(nat_type, NAT_SYMMETRIC); rtc::NATSocketServer::Translator* outer_nat = nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], static_cast(nat_type - NAT_FULL_CONE)); diff --git a/webrtc/p2p/client/basicportallocator.cc b/webrtc/p2p/client/basicportallocator.cc index ce95895e8a..66ee9a4ecf 100644 --- a/webrtc/p2p/client/basicportallocator.cc +++ b/webrtc/p2p/client/basicportallocator.cc @@ -1350,7 +1350,8 @@ void AllocationSequence::CreateRelayPorts() { // If BasicPortAllocatorSession::OnAllocate left relay ports enabled then we // ought to have a relay list for them here. - RTC_DCHECK(config_ && !config_->relays.empty()); + RTC_DCHECK(config_); + RTC_DCHECK(!config_->relays.empty()); if (!(config_ && !config_->relays.empty())) { LOG(LS_WARNING) << "AllocationSequence: No relay server configured, skipping."; diff --git a/webrtc/pc/datachannel.cc b/webrtc/pc/datachannel.cc index ce0aa14d4e..28c090dee6 100644 --- a/webrtc/pc/datachannel.cc +++ b/webrtc/pc/datachannel.cc @@ -282,8 +282,9 @@ void DataChannel::RemotePeerRequestClose() { } void DataChannel::SetSctpSid(int sid) { - RTC_DCHECK(config_.id < 0 && sid >= 0 && - data_channel_type_ == cricket::DCT_SCTP); + RTC_DCHECK_LT(config_.id, 0); + RTC_DCHECK_GE(sid, 0); + RTC_DCHECK_EQ(data_channel_type_, cricket::DCT_SCTP); if (config_.id == sid) { return; } @@ -618,8 +619,10 @@ void DataChannel::QueueControlMessage(const rtc::CopyOnWriteBuffer& buffer) { bool DataChannel::SendControlMessage(const rtc::CopyOnWriteBuffer& buffer) { bool is_open_message = handshake_state_ == kHandshakeShouldSendOpen; - RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP && writable_ && - config_.id >= 0 && (!is_open_message || !config_.negotiated)); + RTC_DCHECK_EQ(data_channel_type_, cricket::DCT_SCTP); + RTC_DCHECK(writable_); + RTC_DCHECK_GE(config_.id, 0); + RTC_DCHECK(!is_open_message || !config_.negotiated); cricket::SendDataParams send_params; send_params.sid = config_.id; diff --git a/webrtc/pc/remoteaudiosource.cc b/webrtc/pc/remoteaudiosource.cc index 8d1a5d0fd4..f6f23c3f24 100644 --- a/webrtc/pc/remoteaudiosource.cc +++ b/webrtc/pc/remoteaudiosource.cc @@ -96,7 +96,8 @@ bool RemoteAudioSource::remote() const { } void RemoteAudioSource::SetVolume(double volume) { - RTC_DCHECK(volume >= 0 && volume <= 10); + RTC_DCHECK_GE(volume, 0); + RTC_DCHECK_LE(volume, 10); for (auto* observer : audio_observers_) observer->OnSetVolume(volume); } diff --git a/webrtc/pc/rtpreceiver.cc b/webrtc/pc/rtpreceiver.cc index c6a2128dfb..99c4010101 100644 --- a/webrtc/pc/rtpreceiver.cc +++ b/webrtc/pc/rtpreceiver.cc @@ -53,7 +53,8 @@ void AudioRtpReceiver::OnChanged() { } void AudioRtpReceiver::OnSetVolume(double volume) { - RTC_DCHECK(volume >= 0 && volume <= 10); + RTC_DCHECK_GE(volume, 0); + RTC_DCHECK_LE(volume, 10); cached_volume_ = volume; if (!channel_) { LOG(LS_ERROR) << "AudioRtpReceiver::OnSetVolume: No audio channel exists."; diff --git a/webrtc/pc/rtpsender.cc b/webrtc/pc/rtpsender.cc index a16a28c193..9d920e6f08 100644 --- a/webrtc/pc/rtpsender.cc +++ b/webrtc/pc/rtpsender.cc @@ -243,7 +243,8 @@ void AudioRtpSender::Stop() { } void AudioRtpSender::SetAudioSend() { - RTC_DCHECK(!stopped_ && can_send_track()); + RTC_DCHECK(!stopped_); + RTC_DCHECK(can_send_track()); if (!channel_) { LOG(LS_ERROR) << "SetAudioSend: No audio channel exists."; return; @@ -430,7 +431,8 @@ void VideoRtpSender::Stop() { } void VideoRtpSender::SetVideoSend() { - RTC_DCHECK(!stopped_ && can_send_track()); + RTC_DCHECK(!stopped_); + RTC_DCHECK(can_send_track()); if (!channel_) { LOG(LS_ERROR) << "SetVideoSend: No video channel exists."; return; diff --git a/webrtc/pc/test/fakedatachannelprovider.h b/webrtc/pc/test/fakedatachannelprovider.h index 89bb987fe0..ecc0aa6c73 100644 --- a/webrtc/pc/test/fakedatachannelprovider.h +++ b/webrtc/pc/test/fakedatachannelprovider.h @@ -26,7 +26,8 @@ class FakeDataChannelProvider : public webrtc::DataChannelProviderInterface { bool SendData(const cricket::SendDataParams& params, const rtc::CopyOnWriteBuffer& payload, cricket::SendDataResult* result) override { - RTC_CHECK(ready_to_send_ && transport_available_); + RTC_CHECK(ready_to_send_); + RTC_CHECK(transport_available_); if (send_blocked_) { *result = cricket::SDR_BLOCK; return false; diff --git a/webrtc/pc/test/fakertccertificategenerator.h b/webrtc/pc/test/fakertccertificategenerator.h index 39b9107448..7b47378313 100644 --- a/webrtc/pc/test/fakertccertificategenerator.h +++ b/webrtc/pc/test/fakertccertificategenerator.h @@ -151,12 +151,12 @@ class FakeRTCCertificateGenerator if (should_fail_) { msg_id = MSG_FAILURE; } else if (key_params.type() == rtc::KT_RSA) { - RTC_DCHECK(key_params.rsa_params().mod_size == 1024 && - key_params.rsa_params().pub_exp == 0x10001); + RTC_DCHECK_EQ(key_params.rsa_params().mod_size, 1024); + RTC_DCHECK_EQ(key_params.rsa_params().pub_exp, 0x10001); msg_id = MSG_SUCCESS_RSA; } else { - RTC_DCHECK(key_params.type() == rtc::KT_ECDSA && - key_params.ec_curve() == rtc::EC_NIST_P256); + RTC_DCHECK_EQ(key_params.type(), rtc::KT_ECDSA); + RTC_DCHECK_EQ(key_params.ec_curve(), rtc::EC_NIST_P256); msg_id = MSG_SUCCESS_ECDSA; } rtc::Thread::Current()->Post(RTC_FROM_HERE, this, msg_id, msg); diff --git a/webrtc/rtc_base/macutils.cc b/webrtc/rtc_base/macutils.cc index 282f7827a0..2e5e1fb363 100644 --- a/webrtc/rtc_base/macutils.cc +++ b/webrtc/rtc_base/macutils.cc @@ -72,7 +72,9 @@ void DecodeFourChar(UInt32 fc, std::string* out) { } static bool GetOSVersion(int* major, int* minor, int* bugfix) { - RTC_DCHECK(major && minor && bugfix); + RTC_DCHECK(major); + RTC_DCHECK(minor); + RTC_DCHECK(bugfix); struct utsname uname_info; if (uname(&uname_info) != 0) return false; diff --git a/webrtc/rtc_base/opensslstreamadapter.cc b/webrtc/rtc_base/opensslstreamadapter.cc index 1c0b57894a..53f35fc802 100644 --- a/webrtc/rtc_base/opensslstreamadapter.cc +++ b/webrtc/rtc_base/opensslstreamadapter.cc @@ -555,7 +555,8 @@ StreamResult OpenSSLStreamAdapter::Write(const void* data, size_t data_len, switch (ssl_error) { case SSL_ERROR_NONE: LOG(LS_VERBOSE) << " -- success"; - RTC_DCHECK(0 < code && static_cast(code) <= data_len); + RTC_DCHECK_GT(code, 0); + RTC_DCHECK_LE(code, data_len); if (written) *written = code; return SR_SUCCESS; @@ -619,7 +620,8 @@ StreamResult OpenSSLStreamAdapter::Read(void* data, size_t data_len, switch (ssl_error) { case SSL_ERROR_NONE: LOG(LS_VERBOSE) << " -- success"; - RTC_DCHECK(0 < code && static_cast(code) <= data_len); + RTC_DCHECK_GT(code, 0); + RTC_DCHECK_LE(code, data_len); if (read) *read = code; diff --git a/webrtc/rtc_base/proxyserver.cc b/webrtc/rtc_base/proxyserver.cc index 18dceac5be..c00e24319e 100644 --- a/webrtc/rtc_base/proxyserver.cc +++ b/webrtc/rtc_base/proxyserver.cc @@ -43,7 +43,8 @@ SocketAddress ProxyServer::GetServerAddress() { } void ProxyServer::OnAcceptEvent(AsyncSocket* socket) { - RTC_DCHECK(socket != nullptr && socket == server_socket_.get()); + RTC_DCHECK(socket); + RTC_DCHECK_EQ(socket, server_socket_.get()); AsyncSocket* int_socket = socket->Accept(nullptr); AsyncProxyServerSocket* wrapped_socket = WrapSocket(int_socket); AsyncSocket* ext_socket = ext_factory_->CreateAsyncSocket(ext_ip_.family(), @@ -84,7 +85,8 @@ ProxyBinding::~ProxyBinding() = default; void ProxyBinding::OnConnectRequest(AsyncProxyServerSocket* socket, const SocketAddress& addr) { - RTC_DCHECK(!connected_ && ext_socket_.get() != nullptr); + RTC_DCHECK(!connected_); + RTC_DCHECK(ext_socket_); ext_socket_->Connect(addr); // TODO: handle errors here } diff --git a/webrtc/rtc_base/socketaddress.cc b/webrtc/rtc_base/socketaddress.cc index 5b26b9f74a..880841410b 100644 --- a/webrtc/rtc_base/socketaddress.cc +++ b/webrtc/rtc_base/socketaddress.cc @@ -9,6 +9,7 @@ */ #include "webrtc/rtc_base/socketaddress.h" +#include "webrtc/rtc_base/safe_conversions.h" #if defined(WEBRTC_POSIX) #include @@ -120,8 +121,7 @@ void SocketAddress::SetResolvedIP(const IPAddress& ip) { } void SocketAddress::SetPort(int port) { - RTC_DCHECK((0 <= port) && (port < 65536)); - port_ = static_cast(port); + port_ = rtc::dchecked_cast(port); } uint32_t SocketAddress::ip() const { diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 9158d362c6..5732e8e523 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -2502,7 +2502,8 @@ void Channel::RegisterSenderCongestionControlObjects( RTC_DCHECK(rtp_packet_sender); RTC_DCHECK(transport_feedback_observer); - RTC_DCHECK(packet_router && !packet_router_); + RTC_DCHECK(packet_router); + RTC_DCHECK(!packet_router_); rtcp_observer_->SetBandwidthObserver(bandwidth_observer); feedback_observer_proxy_->SetTransportFeedbackObserver( transport_feedback_observer); @@ -2516,7 +2517,8 @@ void Channel::RegisterSenderCongestionControlObjects( void Channel::RegisterReceiverCongestionControlObjects( PacketRouter* packet_router) { - RTC_DCHECK(packet_router && !packet_router_); + RTC_DCHECK(packet_router); + RTC_DCHECK(!packet_router_); constexpr bool remb_candidate = false; packet_router->AddReceiveRtpModule(_rtpRtcpModule.get(), remb_candidate); packet_router_ = packet_router;