From 8c4b9eda3383a469ae47b8dedbf5093c5b4e10df Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 5 Oct 2016 09:12:31 +0200 Subject: GLTFIO: check return value of QFile::open() We checked that the file exists prior to opening it, but it could still be unreadable (due to permissions, e.g.), so check with QFile::open() and emit QFile::errorString() in case it goes wrong. Coverity-Id: 161328 Change-Id: I3489488023bb697d6cb9eee6be07c0edd923c478 Reviewed-by: Giuseppe D'Angelo --- src/plugins/sceneparsers/gltf/gltfparser.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/plugins/sceneparsers/gltf/gltfparser.cpp b/src/plugins/sceneparsers/gltf/gltfparser.cpp index 6bfca2b55..e42ebb510 100644 --- a/src/plugins/sceneparsers/gltf/gltfparser.cpp +++ b/src/plugins/sceneparsers/gltf/gltfparser.cpp @@ -196,13 +196,11 @@ bool GLTFParser::setJSON(const QJsonDocument &json ) void GLTFParser::setSource(const QUrl &source) { const QString path = QUrlHelper::urlToLocalFileOrQrc(source); - QFileInfo finfo(path); - if (!finfo.exists()) { - qCWarning(GLTFParserLog) << "missing file:" << path; + QFile f(path); + if (Q_UNLIKELY(!f.open(QIODevice::ReadOnly))) { + qCWarning(GLTFParserLog) << "cannot open " << path << ": " << f.errorString(); return; } - QFile f(path); - f.open(QIODevice::ReadOnly); QByteArray jsonData = f.readAll(); QJsonDocument sceneDocument = QJsonDocument::fromBinaryData(jsonData); @@ -214,7 +212,7 @@ void GLTFParser::setSource(const QUrl &source) return; } - setBasePath(finfo.dir().absolutePath()); + setBasePath(QFileInfo(path).dir().absolutePath()); } /*! -- cgit v1.2.3