From 98cc88c87354c96a88cebbd7b803815b4ebeea95 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Wed, 4 Nov 2015 09:56:17 -0800 Subject: [PATCH] Correctly handle the error case where the CodecId has a negative value Negative values should be treated the same as too-large positive values: by returning an empty Maybe. TBR=henrik.lundin@webrtc.org Review URL: https://codereview.webrtc.org/1407383010 Cr-Commit-Position: refs/heads/master@{#10509} --- webrtc/modules/audio_coding/main/acm2/rent_a_codec.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h index 24ae121a47..50d8c54ab4 100644 --- a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h +++ b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h @@ -133,8 +133,8 @@ class RentACodec { static inline rtc::Maybe CodecIndexFromId(CodecId codec_id) { const int i = static_cast(codec_id); - return i < static_cast(NumberOfCodecs()) ? rtc::Maybe(i) - : rtc::Maybe(); + return i >= 0 && i < static_cast(NumberOfCodecs()) ? rtc::Maybe(i) + : rtc::Maybe(); } static inline rtc::Maybe CodecIdFromIndex(int codec_index) {