projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
inputfile: Use a vector instead of an array on the stack.
[pulseview.git]
/
pv
/
devices
/
inputfile.cpp
diff --git
a/pv/devices/inputfile.cpp
b/pv/devices/inputfile.cpp
index b866deb8245ed1d6051833f897efc2b7d59ee282..1bf34bad22a33bc0307199657bfe5ecf8dc9ef3d 100644
(file)
--- a/
pv/devices/inputfile.cpp
+++ b/
pv/devices/inputfile.cpp
@@
-19,6
+19,7
@@
#include <cassert>
#include <fstream>
#include <cassert>
#include <fstream>
+#include <vector>
#include <QString>
#include <QString>
@@
-30,6
+31,7
@@
using std::streamsize;
using std::string;
using std::ifstream;
using std::ios;
using std::string;
using std::ifstream;
using std::ios;
+using std::vector;
namespace pv {
namespace devices {
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);
// 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<char> buffer(BufferSize);
+
+ f->read(buffer.data(), BufferSize);
const streamsize size = f->gcount();
if (size == 0)
return;
const streamsize size = f->gcount();
if (size == 0)
return;
- input_->send(buffer, size);
+ input_->send(buffer
.data()
, size);
try {
device_ = input_->device();
try {
device_ = input_->device();
@@
-93,22
+96,22
@@
void InputFile::start()
void InputFile::run()
{
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();
}
if (!f) {
// Previous call to run() processed the entire file already
f = new ifstream(file_name_, ios::binary);
input_->reset();
}
+ vector<char> buffer(BufferSize);
+
interrupt_ = false;
while (!interrupt_ && !f->eof()) {
interrupt_ = false;
while (!interrupt_ && !f->eof()) {
- f->read(buffer, BufferSize);
+ f->read(buffer
.data()
, BufferSize);
const streamsize size = f->gcount();
if (size == 0)
break;
const streamsize size = f->gcount();
if (size == 0)
break;
- input_->send(buffer, size);
+ input_->send(buffer
.data()
, size);
if (size != BufferSize)
break;
if (size != BufferSize)
break;