From dfb69b2755a90beb0accd0abb5496f2be19c0131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sat, 15 Apr 2017 11:47:30 +0200 Subject: [PATCH] Yet another error handling fix. --- src/offlinemap.cpp | 4 ++-- src/ozf.cpp | 15 ++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/offlinemap.cpp b/src/offlinemap.cpp index 9c11726e..f4235bf3 100644 --- a/src/offlinemap.cpp +++ b/src/offlinemap.cpp @@ -305,8 +305,8 @@ bool OfflineMap::getImageInfo(const QString &path) } if (_imgPath.endsWith("ozf2")) { - if (_ozf.load(_imgPath)) - _size = _ozf.size(); + _ozf.load(_imgPath); + _size = _ozf.size(); } else { QImageReader img(_imgPath); _size = img.size(); diff --git a/src/ozf.cpp b/src/ozf.cpp index 8cf11907..9664848c 100644 --- a/src/ozf.cpp +++ b/src/ozf.cpp @@ -26,17 +26,12 @@ bool OZF::readHeaders() quint16 magic; quint32 separator; - if (!readValue(magic) || magic != OZF2_MAGIC) { - qWarning("%s: not a OZF2 file", qPrintable(_file.fileName())); - _file.close(); + if (!readValue(magic) || magic != OZF2_MAGIC) return false; - } if (!_file.seek(_file.pos() + 52)) return false; - if (!readValue(separator)) - return false; - if (separator != OZF2_SEPARATOR) + if (!readValue(separator) || separator != OZF2_SEPARATOR) return false; return true; @@ -81,9 +76,8 @@ bool OZF::readTileTable() quint32 b = (bgr0 & 0x000000FF); quint32 g = (bgr0 & 0x0000FF00) >> 8; quint32 r = (bgr0 & 0x00FF0000) >> 16; - quint32 argb = 0xFF000000 | r << 16 | g << 8 | b; - _palette[i] = argb; + _palette[i] = 0xFF000000 | r << 16 | g << 8 | b; } _tiles = QVector(_dim.width() * _dim.height() + 1); @@ -101,12 +95,15 @@ bool OZF::load(const QString &path) return false; if (!readHeaders()) { + qWarning("%s: not a OZF2 file", qPrintable(_file.fileName())); _file.close(); return false; } if (!readTileTable()) { + qWarning("%s: file format error", qPrintable(_file.fileName())); _file.close(); + _size = QSize(); return false; }