From 418cd07e176178301a7ede908a6a5003f1f6a700 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 19 Oct 2019 18:17:44 -0400 Subject: [PATCH] Adds a check against overrunning data. --- Outputs/CRT/CRT.cpp | 3 +++ Outputs/CRT/CRT.hpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 2a129284a..5b45513ea 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -406,6 +406,9 @@ void CRT::set_immediate_default_phase(float phase) { } void CRT::output_data(int number_of_cycles, size_t number_of_samples) { +#ifndef NDEBUG + assert(number_of_samples <= allocated_data_length_); +#endif scan_target_->end_data(number_of_samples); Scan scan; scan.type = Scan::Type::Data; diff --git a/Outputs/CRT/CRT.hpp b/Outputs/CRT/CRT.hpp index 042521cc8..dd5985444 100644 --- a/Outputs/CRT/CRT.hpp +++ b/Outputs/CRT/CRT.hpp @@ -83,6 +83,10 @@ class CRT { Outputs::Display::ScanTarget::Modals scan_target_modals_; static const uint8_t DefaultAmplitude = 80; +#ifndef NDEBUG + size_t allocated_data_length_ = 0; +#endif + public: /*! Constructs the CRT with a specified clock rate, height and colour subcarrier frequency. The requested number of buffers, each with the requested number of bytes per pixel, @@ -221,6 +225,9 @@ class CRT { @returns A pointer to the allocated area if room is available; @c nullptr otherwise. */ inline uint8_t *begin_data(std::size_t required_length, std::size_t required_alignment = 1) { +#ifndef NDEBUG + allocated_data_length_ = required_length; +#endif return scan_target_->begin_data(required_length, required_alignment); }