diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-02-11 14:57:22 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-02-11 14:57:22 +0100 |
commit | e659399f872832552a5fdae02e70f4579f0e266e (patch) | |
tree | d440b56943b5a3173dce66abdd76a876fc85d170 | |
parent | 50e2019c47f2a2be3c194f75aff2c088c425ef5f (diff) | |
download | dabmod-e659399f872832552a5fdae02e70f4579f0e266e.tar.gz dabmod-e659399f872832552a5fdae02e70f4579f0e266e.tar.bz2 dabmod-e659399f872832552a5fdae02e70f4579f0e266e.zip |
Add buffer size check in TimeInterleaver
-rw-r--r-- | src/TimeInterleaver.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
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<unsigned char> 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<const unsigned char*>(dataIn->getData()); unsigned char* out = reinterpret_cast<unsigned char*>(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(); } |