[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Sun Aug 29 17:02:24 CEST 2010
SVN commit 1169534 by kuemmel:
don't trigger msvc assert due to missing \0 at end of read data
M +4 -5 asciisource.cpp
M +9 -4 asciisource.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1169533:1169534
@@ -257,7 +257,6 @@
tmpbuf.resize(tmpbuf.capacity());
int bufstart = _rowIndex[_numFrames];
bufread = readFromFile(file, tmpbuf, bufstart, _byteLength - bufstart, MAXBUFREADLEN);
- tmpbuf[bufread] = '\0';
bool is_comment = false, has_dat = false;
char *comment = strpbrk(tmpbuf.data(), del);
@@ -355,7 +354,7 @@
if (!openValidFile(file)) {
return 0;
}
- readFromFile(file, _tmpBuffer, bufstart, bufread);
+ bufread = readFromFile(file, _tmpBuffer, bufstart, bufread);
if (_config._columnType == AsciiSourceConfig::Fixed) {
for (int i = 0; i < n; ++i, ++s) {
@@ -484,8 +483,8 @@
rc += "INDEX";
- QString columnDelimiter = cfg->_columnDelimiter.value();
- QRegExp regexColumnDelemiter(QString("[%1]").arg(QRegExp::escape(columnDelimiter)));
+ const QString columnDelimiter = cfg->_columnDelimiter.value();
+ const QRegExp regexColumnDelemiter(QString("[%1]").arg(QRegExp::escape(columnDelimiter)));
if (cfg->_readFields) {
int l = cfg->_fieldsLine;
while (!file.atEnd()) {
@@ -518,7 +517,7 @@
regex.setPattern(QString("^\\s*[%1].*").arg(cfg->_delimiters));
}
- QRegExp regexS("\\s");
+ const QRegExp regexS("\\s");
bool done = false;
int skip = cfg->_dataLine;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1169533:1169534
@@ -106,16 +106,21 @@
int AsciiSource::readFromFile(QFile& file, T& buffer, int start, int bytesToRead, int maximalBytes)
{
if (maximalBytes == -1) {
- buffer.resize(bytesToRead);
+ buffer.resize(bytesToRead + 1);
} else {
bytesToRead = qMin(bytesToRead, maximalBytes);
- if (buffer.size() < bytesToRead) {
- buffer.resize(bytesToRead);
+ if (buffer.size() <= bytesToRead) {
+ buffer.resize(bytesToRead + 1);
}
}
file.seek(start); // expensive?
- return file.read(buffer.data(), bytesToRead);
+ int bytesRead = file.read(buffer.data(), bytesToRead);
+ if (buffer.size() <= bytesRead) {
+ buffer.resize(bytesRead + 1);
}
+ buffer.data()[bytesRead] = '\0';
+ return bytesRead;
+}
#endif
More information about the Kst
mailing list