From e659399f872832552a5fdae02e70f4579f0e266e Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 11 Feb 2017 14:57:22 +0100 Subject: Add buffer size check in TimeInterleaver --- src/TimeInterleaver.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/TimeInterleaver.cpp b/src/TimeInterleaver.cpp index 7f44caf..9565eca 100644 --- a/src/TimeInterleaver.cpp +++ b/src/TimeInterleaver.cpp @@ -37,8 +37,7 @@ TimeInterleaver::TimeInterleaver(size_t framesize) throw std::invalid_argument("framesize must be 16 bits multiple"); } for (int i = 0; i < 16; ++i) { - std::vector data(framesize, 0); - d_history.push_back(data); + d_history.emplace_back(framesize, 0); } } @@ -54,11 +53,16 @@ int TimeInterleaver::process(Buffer* const dataIn, Buffer* dataOut) PDEBUG("TimeInterleaver::process(dataIn: %p, dataOut: %p)\n", dataIn, dataOut); + if (dataIn->getLength() != d_framesize) { + throw std::invalid_argument("Interleaver buffer input size " + + std::to_string(dataIn->getLength()) + " expected " + + std::to_string(d_framesize)); + } + dataOut->setLength(dataIn->getLength()); const unsigned char* in = reinterpret_cast(dataIn->getData()); unsigned char* out = reinterpret_cast(dataOut->getData()); - for (size_t i = 0; i < dataOut->getLength();) { d_history.push_front(d_history.back()); d_history.pop_back(); @@ -87,6 +91,6 @@ int TimeInterleaver::process(Buffer* const dataIn, Buffer* dataOut) ++j; } } - + return dataOut->getLength(); } -- cgit v1.2.3