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}
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 24ae121..50d8c54 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 @@
static inline rtc::Maybe<int> CodecIndexFromId(CodecId codec_id) {
const int i = static_cast<int>(codec_id);
- return i < static_cast<int>(NumberOfCodecs()) ? rtc::Maybe<int>(i)
- : rtc::Maybe<int>();
+ return i >= 0 && i < static_cast<int>(NumberOfCodecs()) ? rtc::Maybe<int>(i)
+ : rtc::Maybe<int>();
}
static inline rtc::Maybe<CodecId> CodecIdFromIndex(int codec_index) {