Updater: Fix crash when there is an XML error
authorOlivier Goffart <ogoffart@woboq.com>
Fri, 25 Oct 2019 12:14:47 +0000 (14:14 +0200)
committerCamila (Rebase PR Action) <hello@camila.codes>
Tue, 24 Nov 2020 18:22:33 +0000 (18:22 +0000)
The problem was accessing the lines with an off by one error, while printing
the log.

Other problem included the fact that QDebug added spaces, quotes, and other
things which made the error lot look right in the console.

Issue #7545

src/gui/updater/updateinfo.cpp

index 3b2d5b602fc4a3cff2d7cb8ab6b30c6f38f98b2d..176df1ec27802b1a2931d4bb3bd13a111346cf5a 100644 (file)
@@ -88,9 +88,9 @@ UpdateInfo UpdateInfo::parseString(const QString &xml, bool *ok)
     int errorLine = 0, errorCol = 0;
     QDomDocument doc;
     if (!doc.setContent(xml, false, &errorMsg, &errorLine, &errorCol)) {
-        qCCritical(lcUpdater) << errorMsg << " at " << errorLine << "," << errorCol;
-        qCCritical(lcUpdater()) << "->" << xml.splitRef("\n")[errorLine] << "<-\n"
-                                << QStringLiteral(" ").repeated(2 + errorCol - 1) << "^\n"
+        qCCritical(lcUpdater).noquote().nospace() << errorMsg << " at " << errorLine << "," << errorCol
+                                << "\n" <<  xml.splitRef("\n").value(errorLine-1) << "\n"
+                                << QString(" ").repeated(errorCol - 1) << "^\n"
                                 << "->" << xml << "<-";
         if (ok)
             *ok = false;