Simplified read/verify header process

Where possible, QIODevice::peek has been used instead of transactions or instead of using ungetchar() for sequential access devices and seek() for random access devices.

Furthermore:
- RAS format gained the ability of read on sequential devices.
- Removed unused code in XCF (still related to ungetchar and sequential devices).
- These changes should prevent errors like the ones fixed by MR !258
This commit is contained in:
Mirco Miranda
2024-10-06 17:26:25 +00:00
committed by Albert Astals Cid
parent fee0165bef
commit 97120b2537
7 changed files with 51 additions and 180 deletions

View File

@ -266,31 +266,16 @@ PCXHEADER::PCXHEADER()
bool peekHeader(QIODevice *d, PCXHEADER& h)
{
qint64 oldPos = d->pos();
QByteArray head = d->read(sizeof(PCXHEADER));
int readBytes = head.size();
if (d->isSequential()) {
for (int pos = readBytes -1; pos >= 0; --pos) {
d->ungetChar(head[pos]);
}
} else {
d->seek(oldPos);
}
if (readBytes < sizeof(PCXHEADER)) {
auto head = d->peek(sizeof(PCXHEADER));
if (size_t(head.size()) < sizeof(PCXHEADER)) {
return false;
}
auto ok = false;
{ // datastream is destroyed before working on device
QDataStream ds(head);
ds.setByteOrder(QDataStream::LittleEndian);
ds >> h;
ok = ds.status() == QDataStream::Ok && h.isValid();
}
QDataStream ds(head);
ds.setByteOrder(QDataStream::LittleEndian);
ds >> h;
return ok;
return ds.status() == QDataStream::Ok && h.isValid();
}
static bool readLine(QDataStream &s, QByteArray &buf, const PCXHEADER &header)