From 32319ddf9f778a2a72b66bf093655bb2da24e026 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 1 Dec 2015 16:05:23 -0800 Subject: [PATCH] Manchester decoder bounds checking. Return error symbol if reading past source data. --- firmware/application/ui_receiver.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/firmware/application/ui_receiver.cpp b/firmware/application/ui_receiver.cpp index a135d424..75be6dce 100644 --- a/firmware/application/ui_receiver.cpp +++ b/firmware/application/ui_receiver.cpp @@ -562,9 +562,14 @@ public: } DecodedSymbol operator[](const size_t index) const { - const auto value = encoded[index * 2 + sense]; - const auto error = encoded[index * 2 + 0] == encoded[index * 2 + 1]; - return { value, error }; + const size_t encoded_index = index * 2; + if( (encoded_index + 1) < count ) { + const auto value = encoded[encoded_index + sense]; + const auto error = encoded[encoded_index + 0] == encoded[encoded_index + 1]; + return { value, error }; + } else { + return { 0, 1 }; + } } size_t symbols_count() const {