From: Uwe Hermann Date: Sat, 14 Apr 2018 20:20:43 +0000 (+0200) Subject: inputfile: Use a vector instead of an array on the stack. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3b0acbcbcd902ac61a3841e7c558cbc5f8448b7f;p=pulseview.git inputfile: Use a vector instead of an array on the stack. Increasing the chunk size could cause issues when trying to put large arrays on the stack. --- diff --git a/pv/devices/inputfile.cpp b/pv/devices/inputfile.cpp index b866deb8..1bf34bad 100644 --- a/pv/devices/inputfile.cpp +++ b/pv/devices/inputfile.cpp @@ -19,6 +19,7 @@ #include #include +#include #include @@ -30,6 +31,7 @@ using std::streamsize; using std::string; using std::ifstream; using std::ios; +using std::vector; namespace pv { namespace devices { @@ -64,13 +66,14 @@ void InputFile::open() // we can't open the device without sending some data first f = new ifstream(file_name_, ios::binary); - char buffer[BufferSize]; - f->read(buffer, BufferSize); + vector buffer(BufferSize); + + f->read(buffer.data(), BufferSize); const streamsize size = f->gcount(); if (size == 0) return; - input_->send(buffer, size); + input_->send(buffer.data(), size); try { device_ = input_->device(); @@ -93,22 +96,22 @@ void InputFile::start() void InputFile::run() { - char buffer[BufferSize]; - if (!f) { // Previous call to run() processed the entire file already f = new ifstream(file_name_, ios::binary); input_->reset(); } + vector buffer(BufferSize); + interrupt_ = false; while (!interrupt_ && !f->eof()) { - f->read(buffer, BufferSize); + f->read(buffer.data(), BufferSize); const streamsize size = f->gcount(); if (size == 0) break; - input_->send(buffer, size); + input_->send(buffer.data(), size); if (size != BufferSize) break;