From cb30cee7a065a074394347f112451decc4847674 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 17 Jan 2020 20:25:44 +0200 Subject: Fix various gcc and clazy compile warnings --- lib/about/aboutplugin.cpp | 16 ++++++------- lib/bookmarks/formats/xbel.cpp | 2 +- lib/pluginloader/pluginloader.cpp | 4 ++-- lib/pluginloader/pluginloader.h | 4 +++- lib/urlfilter/adblock/adblocklist.cpp | 44 +++++++++++++++++------------------ lib/urlfilter/adblock/parser.cpp | 26 ++++++++++----------- lib/urlfilter/hostlist/hostlist.cpp | 8 +++---- 7 files changed, 53 insertions(+), 51 deletions(-) (limited to 'lib') diff --git a/lib/about/aboutplugin.cpp b/lib/about/aboutplugin.cpp index b345b75..99c04ec 100644 --- a/lib/about/aboutplugin.cpp +++ b/lib/about/aboutplugin.cpp @@ -13,11 +13,11 @@ QTreeWidgetItem *createItem(const QString &key, const QJsonValue &json, QTreeWidgetItem *parent) { - auto *item = new QTreeWidgetItem(parent, { key, QLatin1Literal("---") }); + auto *item = new QTreeWidgetItem(parent, { key, QLatin1String("---") }); switch(json.type()) { case QJsonValue::Bool: - item->setText(1, json.toBool() ? QLatin1Literal("true") : QLatin1Literal("false")); + item->setText(1, json.toBool() ? QLatin1String("true") : QLatin1String("false")); break; case QJsonValue::Double: @@ -43,11 +43,11 @@ QTreeWidgetItem *createItem(const QString &key, const QJsonValue &json, QTreeWid break; case QJsonValue::Null: - item->setText(1, QLatin1Literal("null")); + item->setText(1, QLatin1String("null")); break; case QJsonValue::Undefined: - item->setText(1, QLatin1Literal("undefined")); + item->setText(1, QLatin1String("undefined")); break; } @@ -92,10 +92,10 @@ AboutPluginDialog::AboutPluginDialog(QPluginLoader *loader, QWidget *parent) } }); - ui->name->setText(metaData[QLatin1Literal("name")].toString()); - ui->author->setText(metaData[QLatin1Literal("author")].toString()); - ui->license->setText(metaData[QLatin1Literal("license")].toString()); - ui->shortcut->setText(metaData[QLatin1Literal("shortcut")].toString()); + ui->name->setText(metaData[QLatin1String("name")].toString()); + ui->author->setText(metaData[QLatin1String("author")].toString()); + ui->license->setText(metaData[QLatin1String("license")].toString()); + ui->shortcut->setText(metaData[QLatin1String("shortcut")].toString()); for(const QString &key : loader->metaData().keys()) { auto *i = createItem(key, loader->metaData()[key], nullptr); diff --git a/lib/bookmarks/formats/xbel.cpp b/lib/bookmarks/formats/xbel.cpp index bac2bc8..7ff79a9 100644 --- a/lib/bookmarks/formats/xbel.cpp +++ b/lib/bookmarks/formats/xbel.cpp @@ -32,7 +32,7 @@ inline void readChildElements(QXmlStreamReader &reader, BookmarkItem *parent) } else if(reader.name() == "folder") { auto *item = new BookmarkItem({}, BookmarkItem::Folder, parent); - item->setExpanded(!(reader.attributes().value("folded") == QLatin1Literal("yes"))); + item->setExpanded(!(reader.attributes().value("folded") == QLatin1String("yes"))); parent->appendChild(item); readChildElements(reader, item); diff --git a/lib/pluginloader/pluginloader.cpp b/lib/pluginloader/pluginloader.cpp index ef17513..c8358bf 100644 --- a/lib/pluginloader/pluginloader.cpp +++ b/lib/pluginloader/pluginloader.cpp @@ -49,7 +49,7 @@ PluginLoader::VerifyState PluginLoader::verify(const char *hashName) const int read = 0; auto *buf = new unsigned char[1024]; while(len > 0) { - read = plugin.read((char*) buf, 1024); + read = plugin.read(reinterpret_cast(buf), 1024); len -= read; rc = EVP_DigestVerifyUpdate(ctx, buf, read); @@ -65,7 +65,7 @@ PluginLoader::VerifyState PluginLoader::verify(const char *hashName) const const int sig_len = sigFile.size(); const auto* sig = [&sigFile, sig_len]() { auto* buf = new unsigned char[sig_len]; - sigFile.read((char*) buf, sig_len); + sigFile.read(reinterpret_cast(buf), sig_len); return buf; }(); sigFile.close(); diff --git a/lib/pluginloader/pluginloader.h b/lib/pluginloader/pluginloader.h index 0c8bcd3..48be61d 100644 --- a/lib/pluginloader/pluginloader.h +++ b/lib/pluginloader/pluginloader.h @@ -40,7 +40,9 @@ public: QString errorString() const { if(signature < requiredSignatureLevel) - return QString("Required signature level: %2; Signature level: %3").arg(QString::number((int) requiredSignatureLevel), QString::number((int) signature)); + return QString("Required signature level: %2; Signature level: %3").arg( + QString::number(static_cast(requiredSignatureLevel)), + QString::number(static_cast(signature))); else return QPluginLoader::errorString(); } diff --git a/lib/urlfilter/adblock/adblocklist.cpp b/lib/urlfilter/adblock/adblocklist.cpp index c749e9e..3be21bd 100644 --- a/lib/urlfilter/adblock/adblocklist.cpp +++ b/lib/urlfilter/adblock/adblocklist.cpp @@ -71,7 +71,7 @@ void AdBlockList::parseLine(const QString& line) if(parsedLine.isEmpty()) return; - if(parsedLine.startsWith(QLatin1Literal("!"))) { + if(parsedLine.startsWith(QLatin1String("!"))) { const auto comment = parseComment(parsedLine); if(comment) { @@ -84,7 +84,7 @@ void AdBlockList::parseLine(const QString& line) } // css rule -> filterleaves cannot do element blocking - if(parsedLine.contains(QLatin1Literal("##")) || parsedLine.contains(QLatin1Literal("#@#"))) { + if(parsedLine.contains(QLatin1String("##")) || parsedLine.contains(QLatin1String("#@#"))) { qDebug("TODO: %s", qUtf8Printable(parsedLine)); return; } @@ -93,7 +93,7 @@ void AdBlockList::parseLine(const QString& line) r.action = UrlFilter::Block; // exception rules - if(parsedLine.startsWith(QLatin1Literal("@@"))) { + if(parsedLine.startsWith(QLatin1String("@@"))) { r.action = UrlFilter::Allow; parsedLine.remove(0, 2); } @@ -102,24 +102,24 @@ void AdBlockList::parseLine(const QString& line) // parse options { - const int sepPos = parsedLine.indexOf(QLatin1Literal("$")); + const int sepPos = parsedLine.indexOf(QLatin1String("$")); if(sepPos != -1) { - const auto options = parsedLine.mid(sepPos + 1).split(QLatin1Literal(",")); + const auto options = parsedLine.mid(sepPos + 1).split(QLatin1String(",")); parsedLine = parsedLine.mid(0, sepPos); for(const QString &option : options) { - if(option.startsWith(QLatin1Literal("domain"))) { - const auto domainList = option.mid(7).split(QLatin1Literal("|")); + if(option.startsWith(QLatin1String("domain"))) { + const auto domainList = option.mid(7).split(QLatin1String("|")); for(const QString &domain : domainList) { - if(domain.startsWith(QLatin1Literal("~"))) { + if(domain.startsWith(QLatin1String("~"))) { r.disabledOn.append(domain.mid(1)); } else { r.enabledOn.append(domain); } } - } else if(option.endsWith(QLatin1Literal("match-case"))) { - matchCase = !option.startsWith(QLatin1Literal("~")); + } else if(option.endsWith(QLatin1String("match-case"))) { + matchCase = !option.startsWith(QLatin1String("~")); } else { const auto pair = parseResourceOption(option); @@ -130,26 +130,26 @@ void AdBlockList::parseLine(const QString& line) } } - if(parsedLine.startsWith(QLatin1Literal("/")) && parsedLine.endsWith(QLatin1Literal("/"))) { + if(parsedLine.startsWith(QLatin1String("/")) && parsedLine.endsWith(QLatin1String("/"))) { // regular expression rule parsedLine = parsedLine.mid(1, parsedLine.length() - 2); r.matcher = new ContentsMatcher(parsedLine, UrlFilter::RegularExpressionMatch); - } else if(parsedLine.startsWith(QLatin1Literal("||")) && parsedLine.endsWith(QLatin1Literal("^"))) { + } else if(parsedLine.startsWith(QLatin1String("||")) && parsedLine.endsWith(QLatin1String("^"))) { parsedLine = parsedLine.mid(2, parsedLine.length() - 3); r.matcher = new ContentsMatcher(parsedLine, UrlFilter::DomainMatch); - } else if(parsedLine.startsWith(QLatin1Literal("|")) && parsedLine.endsWith(QLatin1Literal("|"))) { + } else if(parsedLine.startsWith(QLatin1String("|")) && parsedLine.endsWith(QLatin1String("|"))) { // string equals rule parsedLine = parsedLine.mid(1, parsedLine.length() - 2); r.matcher = new ContentsMatcher(parsedLine, UrlFilter::StringEquals); - } else if(parsedLine.startsWith(QLatin1Literal("||"))) { + } else if(parsedLine.startsWith(QLatin1String("||"))) { // string starts with rule parsedLine = parsedLine.mid(2); r.matcher = new ContentsMatcher(parsedLine, UrlFilter::StringStartsWith); - } else if(parsedLine.endsWith(QLatin1Literal("|"))) { + } else if(parsedLine.endsWith(QLatin1String("|"))) { // string ends with rule parsedLine.chop(1); r.matcher = new ContentsMatcher(parsedLine, UrlFilter::StringEndsWith); @@ -158,20 +158,20 @@ void AdBlockList::parseLine(const QString& line) // generic contains rule // remove beginning and ending wildcards - if(parsedLine.startsWith(QLatin1Literal("*"))) + if(parsedLine.startsWith(QLatin1String("*"))) parsedLine = parsedLine.mid(1); - if(parsedLine.endsWith(QLatin1Literal("*"))) + if(parsedLine.endsWith(QLatin1String("*"))) parsedLine.chop(1); - if(parsedLine.contains(QLatin1Literal("*")) || parsedLine.contains(QLatin1Literal("^"))) { + if(parsedLine.contains(QLatin1String("*")) || parsedLine.contains(QLatin1String("^"))) { // check for wildcards and translate to regexp // wildcard "*" - any number of characters // separator "^" - end, ? or / - parsedLine.replace(QLatin1Literal("||"), QLatin1Literal("^\\w+://")); - parsedLine.replace(QLatin1Literal("|"), QLatin1Literal("\\|")); - parsedLine.replace(QLatin1Literal("*"), QLatin1Literal(".*")); - parsedLine.replace(QLatin1Literal("^"), QLatin1Literal("($|\\?|\\/)")); + parsedLine.replace(QLatin1String("||"), QLatin1String("^\\w+://")); + parsedLine.replace(QLatin1String("|"), QLatin1String("\\|")); + parsedLine.replace(QLatin1String("*"), QLatin1String(".*")); + parsedLine.replace(QLatin1String("^"), QLatin1String("($|\\?|\\/)")); r.matcher = new ContentsMatcher(parsedLine, UrlFilter::RegularExpressionMatch); diff --git a/lib/urlfilter/adblock/parser.cpp b/lib/urlfilter/adblock/parser.cpp index d65a2e4..68f895d 100644 --- a/lib/urlfilter/adblock/parser.cpp +++ b/lib/urlfilter/adblock/parser.cpp @@ -20,53 +20,53 @@ std::optional> parseComment(QString &line) std::optional> parseResourceOption(const QString &option) { - const bool exception = !option.startsWith(QLatin1Literal("~")); + const bool exception = !option.startsWith(QLatin1String("~")); - if(option.endsWith(QLatin1Literal("script"))) { + if(option.endsWith(QLatin1String("script"))) { // external scripts loaded via HTML script tag return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeScript, exception); - } else if(option.endsWith(QLatin1Literal("image"))) { + } else if(option.endsWith(QLatin1String("image"))) { // regular images, typically loaded via HTML img tag return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeImage, exception); - } else if(option.endsWith(QLatin1Literal("stylesheet"))) { + } else if(option.endsWith(QLatin1String("stylesheet"))) { // external CSS stylesheet files return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeStylesheet, exception); - } else if(option.endsWith(QLatin1Literal("object"))) { + } else if(option.endsWith(QLatin1String("object"))) { // content handled by browser plugins, e.g. Flash or Java return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeObject, exception); - } else if(option.endsWith(QLatin1Literal("xmlhttprequest"))) { + } else if(option.endsWith(QLatin1String("xmlhttprequest"))) { // requests started using the XMLHttpRequest object or fetch() API return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeXhr, exception); - } else if(option.endsWith(QLatin1Literal("object-subrequest"))) { + } else if(option.endsWith(QLatin1String("object-subrequest"))) { // requests started by plugins like Flash return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypePluginResource, exception); - } else if(option.endsWith(QLatin1Literal("subdocument"))) { + } else if(option.endsWith(QLatin1String("subdocument"))) { // embedded pages, usually included via HTML frames return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeSubFrame, exception); - } else if(option.endsWith(QLatin1Literal("ping"))) { + } else if(option.endsWith(QLatin1String("ping"))) { // requests started by or navigator.sendBeacon() return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypePing, exception); - } else if(option.endsWith(QLatin1Literal("websocket"))) { + } else if(option.endsWith(QLatin1String("websocket"))) { // requests initiated via WebSocket object qDebug("Resource type 'websocket' not available"); - } else if(option.endsWith(QLatin1Literal("webrtc"))) { + } else if(option.endsWith(QLatin1String("webrtc"))) { // connections opened via RTCPeerConnection instances to ICE servers qDebug("Resource type 'webrtc' not available"); - } else if(option.endsWith(QLatin1Literal("document"))) { + } else if(option.endsWith(QLatin1String("document"))) { // the page itself return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeMainFrame, exception); - } else if(option.endsWith(QLatin1Literal("other"))) { + } else if(option.endsWith(QLatin1String("other"))) { return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeUnknown, exception); } diff --git a/lib/urlfilter/hostlist/hostlist.cpp b/lib/urlfilter/hostlist/hostlist.cpp index ff652cf..bec79ea 100644 --- a/lib/urlfilter/hostlist/hostlist.cpp +++ b/lib/urlfilter/hostlist/hostlist.cpp @@ -52,18 +52,18 @@ std::pair HostList::match(const QUrl& firstPart void HostList::parseLine(const QString& line) { // check comment - if(line.startsWith(QLatin1Literal("#"))) + if(line.startsWith(QLatin1String("#"))) return; QString parsedLine = line.trimmed(); // malformed rule - if(!parsedLine.contains(QLatin1Literal(" "))) + if(!parsedLine.contains(QLatin1String(" "))) return; - const QStringList parts = parsedLine.split(QLatin1Literal(" ")); + const QStringList parts = parsedLine.split(QLatin1String(" ")); const QString &redirect = parts.at(0); - const auto action = (redirect == QLatin1Literal("0.0.0.0")) ? UrlFilter::Block : UrlFilter::Redirect; + const auto action = (redirect == QLatin1String("0.0.0.0")) ? UrlFilter::Block : UrlFilter::Redirect; for(int i = 1; i < parts.size(); i++) { const QString &domain = parts.at(i); -- cgit v1.2.1