From 9571434df97794b5291470ea41791a715d7a153a Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sun, 3 Apr 2022 01:17:08 -0700 Subject: [PATCH] feat(CI): Disallow unsafe implicit casts to QString Covers char* without size, and QByteArray. Catches the case of QByteArray to QString implicit conversion like was fixed in 47ee51c61d99a7f3b0a8c63fa4d7bbfc32fb2a6d, but still allows construction or assignment from string literals in source. Gives most of the type safety of QT_NO_CAST_FROM_ASCII without having to wrap every literal string in QStringLiteral. No functional issues found during change. --- CMakeLists.txt | 1 + src/chatlog/chatwidget.cpp | 2 +- src/chatlog/content/filetransferwidget.cpp | 2 +- src/core/chatid.cpp | 2 +- src/core/corefile.cpp | 2 +- src/core/toxid.cpp | 6 ++--- src/core/toxlogger.cpp | 2 +- src/ipc.cpp | 2 +- src/main.cpp | 10 ++++---- src/model/message.cpp | 4 +-- src/net/bootstrapnodeupdater.cpp | 2 +- src/persistence/db/rawdatabase.cpp | 10 ++++---- src/persistence/profile.cpp | 2 +- src/persistence/serialize.cpp | 2 +- src/persistence/toxsave.cpp | 2 +- src/platform/camera/directshow.cpp | 4 +-- src/platform/camera/v4l2.cpp | 4 +-- src/video/cameradevice.cpp | 28 ++++++++++----------- src/widget/form/chatform.cpp | 2 +- src/widget/form/profileform.cpp | 2 +- src/widget/form/settings/aboutform.cpp | 2 +- src/widget/friendwidget.cpp | 2 +- src/widget/imagepreviewwidget.cpp | 2 +- src/widget/style.cpp | 4 +-- src/widget/widget.cpp | 8 +++--- test/model/friendmessagedispatcher_test.cpp | 2 +- test/persistence/smileypack_test.cpp | 2 +- util/src/display.cpp | 2 +- 28 files changed, 58 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c2a94938c..ea3952610c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ endif() add_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) add_definitions(-DQT_NO_CAST_TO_ASCII) +add_definitions(-DQT_RESTRICTED_CAST_FROM_ASCII) include(CheckAtomic) diff --git a/src/chatlog/chatwidget.cpp b/src/chatlog/chatwidget.cpp index e52c9ab3e7..517b0c259a 100644 --- a/src/chatlog/chatwidget.cpp +++ b/src/chatlog/chatwidget.cpp @@ -690,7 +690,7 @@ QString ChatWidget::getSelectedText() const QString msg = line->content[1]->getText(); out += - QString(out.isEmpty() ? "[%2] %1: %3" : "\n[%2] %1: %3").arg(author, timestamp, msg); + QString(out.isEmpty() ? QStringLiteral("[%2] %1: %3") : QStringLiteral("\n[%2] %1: %3")).arg(author, timestamp, msg); }); return out; diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index fd517ca70e..21a51beffa 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -328,7 +328,7 @@ void FileTransferWidget::updateFileProgress(ToxFile const& file) if (speed > 0) { // ETA QTime toGo = QTime(0, 0).addSecs(remainingTime); - QString format = toGo.hour() > 0 ? "hh:mm:ss" : "mm:ss"; + QString format = toGo.hour() > 0 ? QStringLiteral("hh:mm:ss") : QStringLiteral("mm:ss"); ui->etaLabel->setText(toGo.toString(format)); } else { ui->etaLabel->setText(""); diff --git a/src/core/chatid.cpp b/src/core/chatid.cpp index c7a9ec96a6..0fb4ea9952 100644 --- a/src/core/chatid.cpp +++ b/src/core/chatid.cpp @@ -77,7 +77,7 @@ bool ChatId::operator<(const ChatId& other) const */ QString ChatId::toString() const { - return id.toHex().toUpper(); + return QString::fromUtf8(id.toHex()).toUpper(); } /** diff --git a/src/core/corefile.cpp b/src/core/corefile.cpp index 688766d16c..f24387e9c7 100644 --- a/src/core/corefile.cpp +++ b/src/core/corefile.cpp @@ -379,7 +379,7 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI #endif qDebug() << QString("Received file request %1:%2 kind %3").arg(friendId).arg(fileId).arg(kind); - ToxFile file{fileId, friendId, filename.getBytes(), "", filesize, ToxFile::RECEIVING}; + ToxFile file{fileId, friendId, filename.getQString(), "", filesize, ToxFile::RECEIVING}; file.fileKind = kind; file.resumeFileId.resize(TOX_FILE_ID_LENGTH); Tox_Err_File_Get fileGetErr; diff --git a/src/core/toxid.cpp b/src/core/toxid.cpp index 759e5a9c06..33ea76b937 100644 --- a/src/core/toxid.cpp +++ b/src/core/toxid.cpp @@ -114,7 +114,7 @@ ToxId::ToxId(const uint8_t* rawId, int len) void ToxId::constructToxId(const QByteArray& rawId) { - if (rawId.length() == ToxId::size && isToxId(rawId.toHex().toUpper())) { + if (rawId.length() == ToxId::size && isToxId(QString::fromUtf8(rawId.toHex()).toUpper())) { toxId = QByteArray(rawId); // construct from full toxid } else { assert(!"ToxId constructed with invalid input"); @@ -149,7 +149,7 @@ bool ToxId::operator!=(const ToxId& other) const */ QString ToxId::toString() const { - return toxId.toHex().toUpper(); + return QString::fromUtf8(toxId.toHex()).toUpper(); } /** @@ -194,7 +194,7 @@ ToxPk ToxId::getPublicKey() const QString ToxId::getNoSpamString() const { if (toxId.length() == ToxId::size) { - return toxId.mid(ToxPk::size, ToxId::nospamSize).toHex().toUpper(); + return QString::fromUtf8(toxId.mid(ToxPk::size, ToxId::nospamSize).toHex()).toUpper(); } return {}; diff --git a/src/core/toxlogger.cpp b/src/core/toxlogger.cpp index 20968ee6d5..548ce0b558 100644 --- a/src/core/toxlogger.cpp +++ b/src/core/toxlogger.cpp @@ -33,7 +33,7 @@ QByteArray cleanPath(const char *file) { // for privacy, make the path relative to the c-toxcore source directory const QRegularExpression pathCleaner(QLatin1String{"[\\s|\\S]*c-toxcore."}); - QByteArray cleanedPath = QString{file}.remove(pathCleaner).toUtf8(); + QByteArray cleanedPath = QString::fromUtf8(file).remove(pathCleaner).toUtf8(); cleanedPath.append('\0'); return cleanedPath; } diff --git a/src/ipc.cpp b/src/ipc.cpp index b5b7bd9c7e..69f193d027 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -52,7 +52,7 @@ namespace qWarning() << "Failed to get current username. Will use a global IPC."; user = ""; } - return QString("qtox-" IPC_PROTOCOL_VERSION "-") + user; + return QString("qtox-" IPC_PROTOCOL_VERSION "-") + QString::fromUtf8(user); } } // namespace diff --git a/src/main.cpp b/src/main.cpp index 6b5032b6cf..47b3018f0b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -95,7 +95,7 @@ void cleanup() void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QString& msg) { // Silence qWarning spam due to bug in QTextBrowser (trying to open a file for base64 images) - if (ctxt.function == QString("virtual bool QFSFileEngine::open(QIODevice::OpenMode)") + if (QString::fromUtf8(ctxt.function) == QString("virtual bool QFSFileEngine::open(QIODevice::OpenMode)") && msg == QString("QFSFileEngine::open: No file name specified")) { return; } @@ -119,7 +119,7 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QSt return; } - QString file = ctxt.file; + QString file = QString::fromUtf8(ctxt.file); // We're not using QT_MESSAGELOG_FILE here, because that can be 0, NULL, or // nullptr in release builds. QString path = QString(__FILE__); @@ -199,7 +199,7 @@ bool toxURIEventHandler(const QByteArray& eventData, void* userData) return false; } - uriDialog->handleToxURI(eventData); + uriDialog->handleToxURI(QString::fromUtf8(eventData)); return true; } @@ -438,9 +438,9 @@ int main(int argc, char* argv[]) // Event was not handled by already running instance therefore we handle it ourselves if (eventType == "uri") { - uriDialog->handleToxURI(firstParam.toUtf8()); + uriDialog->handleToxURI(firstParam); } else if (eventType == "save") { - toxSave->handleToxSave(firstParam.toUtf8()); + toxSave->handleToxSave(firstParam); } QObject::connect(a.get(), &QApplication::aboutToQuit, cleanup); diff --git a/src/model/message.cpp b/src/model/message.cpp index 9b1530a369..7fb0a205f3 100644 --- a/src/model/message.cpp +++ b/src/model/message.cpp @@ -47,11 +47,11 @@ namespace { } --splitPos; } - splittedMsgs.append(QString{ba_message.left(splitPos + 1)}); + splittedMsgs.append(QString::fromUtf8(ba_message.left(splitPos + 1))); ba_message = ba_message.mid(splitPos + 1); } - splittedMsgs.append(QString{ba_message}); + splittedMsgs.append(QString::fromUtf8(ba_message)); return splittedMsgs; } } diff --git a/src/net/bootstrapnodeupdater.cpp b/src/net/bootstrapnodeupdater.cpp index bd3c640e6f..8e4e351101 100644 --- a/src/net/bootstrapnodeupdater.cpp +++ b/src/net/bootstrapnodeupdater.cpp @@ -163,7 +163,7 @@ QList loadNodesFile(QString file) return {}; } - QString nodesJson = nodesFile.readAll(); + QString nodesJson = QString::fromUtf8(nodesFile.readAll()); nodesFile.close(); auto jsonDoc = QJsonDocument::fromJson(nodesJson.toUtf8()); diff --git a/src/persistence/db/rawdatabase.cpp b/src/persistence/db/rawdatabase.cpp index acab5cfe29..4776fe402a 100644 --- a/src/persistence/db/rawdatabase.cpp +++ b/src/persistence/db/rawdatabase.cpp @@ -696,7 +696,7 @@ QString RawDatabase::deriveKey(const QString& password) const std::unique_ptr key(tox_pass_key_derive_with_salt( reinterpret_cast(passData.data()), static_cast(passData.size()), expandConstant, nullptr)); - return QByteArray(reinterpret_cast(key.get()) + 32, 32).toHex(); + return QString::fromUtf8(QByteArray(reinterpret_cast(key.get()) + 32, 32).toHex()); } /** @@ -724,7 +724,7 @@ QString RawDatabase::deriveKey(const QString& password, const QByteArray& salt) reinterpret_cast(passData.data()), static_cast(passData.size()), reinterpret_cast(salt.constData()), nullptr)); - return QByteArray(reinterpret_cast(key.get()) + 32, 32).toHex(); + return QString::fromUtf8(QByteArray(reinterpret_cast(key.get()) + 32, 32).toHex()); } /** @@ -876,7 +876,7 @@ void RawDatabase::process() */ QString RawDatabase::anonymizeQuery(const QByteArray& query) { - QString queryString(query); + QString queryString = QString::fromUtf8(query); queryString.replace(QRegularExpression("chat.public_key='[A-F0-9]{64}'"), "char.public_key=''"); queryString.replace(QRegularExpression("timestamp BETWEEN \\d{5,} AND \\d{5,}"), @@ -935,8 +935,8 @@ void RawDatabase::regexp(sqlite3_context* ctx, int argc, sqlite3_value** argv, c { std::ignore = argc; QRegularExpression regex; - const QString str1(reinterpret_cast(sqlite3_value_text(argv[0]))); - const QString str2(reinterpret_cast(sqlite3_value_text(argv[1]))); + const QString str1 = QString::fromUtf8(reinterpret_cast(sqlite3_value_text(argv[0]))); + const QString str2 = QString::fromUtf8(reinterpret_cast(sqlite3_value_text(argv[1]))); regex.setPattern(str1); regex.setPatternOptions(cs); diff --git a/src/persistence/profile.cpp b/src/persistence/profile.cpp index 4f4e098691..8e4311490d 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -553,7 +553,7 @@ QString Profile::avatarPath(const ToxPk& owner, bool forceUnencrypted) QByteArray hash(hashSize, 0); crypto_generichash(reinterpret_cast(hash.data()), hashSize, reinterpret_cast(idData.data()), idData.size(), reinterpret_cast(pubkeyData.data()), pubkeyData.size()); - return paths.getSettingsDirPath() + "avatars/" + hash.toHex().toUpper() + ".png"; + return paths.getSettingsDirPath() + "avatars/" + QString::fromUtf8(hash.toHex()).toUpper() + ".png"; } /** diff --git a/src/persistence/serialize.cpp b/src/persistence/serialize.cpp index 8aeb903857..7638b29d07 100644 --- a/src/persistence/serialize.cpp +++ b/src/persistence/serialize.cpp @@ -44,7 +44,7 @@ QString dataToString(QByteArray data) data.remove(0, i); data.truncate(strlen); - return QString(data); + return QString::fromUtf8(data); } uint64_t dataToUint64(const QByteArray& data) diff --git a/src/persistence/toxsave.cpp b/src/persistence/toxsave.cpp index 91d8fac408..45c8597216 100644 --- a/src/persistence/toxsave.cpp +++ b/src/persistence/toxsave.cpp @@ -36,7 +36,7 @@ bool ToxSave::toxSaveEventHandler(const QByteArray& eventData, void* userData) return false; } - toxSave->handleToxSave(eventData); + toxSave->handleToxSave(QString::fromUtf8(eventData)); return true; } diff --git a/src/platform/camera/directshow.cpp b/src/platform/camera/directshow.cpp index 268cb34bb0..3c2ab01099 100644 --- a/src/platform/camera/directshow.cpp +++ b/src/platform/camera/directshow.cpp @@ -99,7 +99,7 @@ QVector> DirectShow::getDeviceList() goto fail; devHumanName = wcharToUtf8(var.bstrVal); - devices += {QString("video=") + devIdString, devHumanName}; + devices += {QString("video=") + QString::fromUtf8(devIdString), QString::fromUtf8(devHumanName)}; fail: if (olestr && coMalloc) @@ -156,7 +156,7 @@ static IBaseFilter* getDevFilter(QString devName) if (devIdString[i] == ':') devIdString[i] = '_'; - if (devName != devIdString) + if (devName.toUtf8().constData() != devIdString) goto fail; if (m->BindToObject(nullptr, nullptr, IID_IBaseFilter, reinterpret_cast(&devFilter)) != S_OK) diff --git a/src/platform/camera/v4l2.cpp b/src/platform/camera/v4l2.cpp index 71cb5e8059..f6effb5284 100644 --- a/src/platform/camera/v4l2.cpp +++ b/src/platform/camera/v4l2.cpp @@ -195,7 +195,7 @@ QVector> v4l2::getDeviceList() dirent* e; while ((e = readdir(dir))) if (!strncmp(e->d_name, "video", 5) || !strncmp(e->d_name, "vbi", 3)) - deviceFiles += QString("/dev/") + e->d_name; + deviceFiles += QString("/dev/") + QString::fromUtf8(e->d_name); closedir(dir); for (QString file : deviceFiles) { @@ -210,7 +210,7 @@ QVector> v4l2::getDeviceList() close(fd); if (caps.device_caps & V4L2_CAP_VIDEO_CAPTURE) - devices += {file, reinterpret_cast(caps.card)}; + devices += {file, QString::fromUtf8(reinterpret_cast(caps.card))}; } return devices; } diff --git a/src/video/cameradevice.cpp b/src/video/cameradevice.cpp index 98e3c40db5..d2900cadb3 100644 --- a/src/video/cameradevice.cpp +++ b/src/video/cameradevice.cpp @@ -195,7 +195,7 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode) devName += QString("+%1,%2").arg(QString().setNum(mode.x), QString().setNum(mode.y)); av_dict_set(&options, "framerate", framerate.c_str(), 0); - } else if (iformat->name == QString("video4linux2,v4l2") && mode) { + } else if (QString::fromUtf8(iformat->name) == QString("video4linux2,v4l2") && mode) { av_dict_set(&options, "video_size", videoSize.c_str(), 0); av_dict_set(&options, "framerate", framerate.c_str(), 0); const std::string pixelFormatStr = v4l2::getPixelFormatString(mode.pixel_format).toStdString(); @@ -215,13 +215,13 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode) av_dict_set(&options, "offset_x", offsetX.c_str(), 0); av_dict_set(&options, "offset_y", offsetY.c_str(), 0); av_dict_set(&options, "video_size", videoSize.c_str(), 0); - } else if (iformat->name == QString("dshow") && mode) { + } else if (QString::fromUtf8(iformat->name) == QString("dshow") && mode) { av_dict_set(&options, "video_size", videoSize.c_str(), 0); av_dict_set(&options, "framerate", framerate.c_str(), 0); } #endif #ifdef Q_OS_OSX - else if (iformat->name == QString("avfoundation")) { + else if (QString::fromUtf8(iformat->name) == QString("avfoundation")) { if (mode) { av_dict_set(&options, "video_size", videoSize.c_str(), 0); av_dict_set(&options, "framerate", framerate.c_str(), 0); @@ -330,8 +330,8 @@ QVector> CameraDevice::getRawDeviceListGeneric() devices.resize(devlist->nb_devices); for (int i = 0; i < devlist->nb_devices; ++i) { AVDeviceInfo* dev = devlist->devices[i]; - devices[i].first = dev->device_name; - devices[i].second = dev->device_description; + devices[i].first = QString::fromUtf8(dev->device_name); + devices[i].second = QString::fromUtf8(dev->device_description); } avdevice_free_list_devices(&devlist); return devices; @@ -354,34 +354,34 @@ QVector> CameraDevice::getDeviceList() if (!iformat) ; #ifdef Q_OS_WIN - else if (iformat->name == QString("dshow")) + else if (QString::fromUtf8(iformat->name) == QString("dshow")) devices += DirectShow::getDeviceList(); #endif #if USING_V4L - else if (iformat->name == QString("video4linux2,v4l2")) + else if (QString::fromUtf8(iformat->name) == QString("video4linux2,v4l2")) devices += v4l2::getDeviceList(); #endif #ifdef Q_OS_OSX - else if (iformat->name == QString("avfoundation")) + else if (QString::fromUtf8(iformat->name) == QString("avfoundation")) devices += avfoundation::getDeviceList(); #endif else devices += getRawDeviceListGeneric(); if (idesktopFormat) { - if (idesktopFormat->name == QString("x11grab")) { + if (QString::fromUtf8(idesktopFormat->name) == QString("x11grab")) { QString dev = "x11grab#"; QByteArray display = qgetenv("DISPLAY"); if (display.isNull()) dev += ":0"; else - dev += display.constData(); + dev += QString::fromUtf8(display.constData()); devices.push_back(QPair{ dev, QObject::tr("Desktop", "Desktop as a camera input for screen sharing")}); } - if (idesktopFormat->name == QString("gdigrab")) + if (QString::fromUtf8(idesktopFormat->name) == QString("gdigrab")) devices.push_back(QPair{ "gdigrab#desktop", QObject::tr("Desktop", "Desktop as a camera input for screen sharing")}); @@ -459,15 +459,15 @@ QVector CameraDevice::getVideoModes(QString devName) else if (isScreen(devName)) return getScreenModes(); #ifdef Q_OS_WIN - else if (iformat->name == QString("dshow")) + else if (QString::fromUtf8(iformat->name) == QString("dshow")) return DirectShow::getDeviceModes(devName); #endif #if USING_V4L - else if (iformat->name == QString("video4linux2,v4l2")) + else if (QString::fromUtf8(iformat->name) == QString("video4linux2,v4l2")) return v4l2::getDeviceModes(devName); #endif #ifdef Q_OS_OSX - else if (iformat->name == QString("avfoundation")) + else if (QString::fromUtf8(iformat->name) == QString("avfoundation")) return avfoundation::getDeviceModes(devName); #endif else diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 50143f4eef..fa7a3b5fe3 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -288,7 +288,7 @@ void ChatForm::onTextEditChanged() void ChatForm::onAttachClicked() { QStringList paths = QFileDialog::getOpenFileNames(Q_NULLPTR, tr("Send a file"), - QDir::homePath(), nullptr, nullptr); + QDir::homePath(), QString(), nullptr); if (paths.isEmpty()) { return; diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index fdd9e95153..9f02736c59 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -302,7 +302,7 @@ QString ProfileForm::getSupportedImageFilter() { QString res; for (auto type : QImageReader::supportedImageFormats()) { - res += QString("*.%1 ").arg(QString(type)); + res += QString("*.%1 ").arg(QString::fromUtf8(type)); } return tr("Images (%1)", "filetype filter").arg(res.left(res.size() - 1)); diff --git a/src/widget/form/settings/aboutform.cpp b/src/widget/form/settings/aboutform.cpp index 601368f07f..2b874051e9 100644 --- a/src/widget/form/settings/aboutform.cpp +++ b/src/widget/form/settings/aboutform.cpp @@ -157,7 +157,7 @@ void AboutForm::replaceVersions() "Replaces `%2` in the `A list of all known…`")))); bodyUI->clickToReport->setText( - createLink("https://github.com/qTox/qTox/issues/new?body=" + QUrl(issueBody).toEncoded(), + createLink("https://github.com/qTox/qTox/issues/new?body=" + QString::fromUtf8(QUrl(issueBody).toEncoded()), QString("%1").arg(tr("Click here to report a bug.")))); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 6fbc4bb85d..787fe4b2ae 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -434,7 +434,7 @@ void FriendWidget::onAvatarRemoved(const ToxPk& friendPk) isDefaultAvatar = true; - const QString path = QString(":/img/contact%1.svg").arg(isActive() ? "_dark" : ""); + const QString path = QString(":/img/contact%1.svg").arg(isActive() ? QStringLiteral("_dark") : QString()); avatar->setPixmap(QPixmap(path)); } diff --git a/src/widget/imagepreviewwidget.cpp b/src/widget/imagepreviewwidget.cpp index e4f887857f..a0d8ff3e93 100644 --- a/src/widget/imagepreviewwidget.cpp +++ b/src/widget/imagepreviewwidget.cpp @@ -98,7 +98,7 @@ QString getToolTipDisplayingImage(const QPixmap& image) previewImage.save(&buffer, "PNG"); buffer.close(); - return ""; + return ""; } } // namespace diff --git a/src/widget/style.cpp b/src/widget/style.cpp index 30abb6bed7..fa8874f6ca 100644 --- a/src/widget/style.cpp +++ b/src/widget/style.cpp @@ -233,7 +233,7 @@ const QString Style::resolve(const QString& filename, Settings& settings, const QFile file{fullPath}; if (file.open(QFile::ReadOnly | QFile::Text)) { - qss = file.readAll(); + qss = QString::fromUtf8(file.readAll()); } else { qWarning() << "Failed to open file:" << fullPath; @@ -241,7 +241,7 @@ const QString Style::resolve(const QString& filename, Settings& settings, const QFile defaultFile{fullPath}; if (defaultFile.open(QFile::ReadOnly | QFile::Text)) { - qss = defaultFile.readAll(); + qss = QString::fromUtf8(defaultFile.readAll()); } else { qWarning() << "Failed to open default file:" << fullPath; return {}; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 6171443e38..5cfcea5bc6 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -556,7 +556,7 @@ void Widget::updateIcons() const QString assetSuffix = Status::getAssetSuffix(static_cast( ui->statusButton->property("status").toInt())) - + (eventIcon ? "_event" : ""); + + (eventIcon ? QStringLiteral("_event") : QString()); // Some builds of Qt appear to have a bug in icon loading: // QIcon::hasThemeIcon is sometimes unaware that the icon returned @@ -588,7 +588,7 @@ void Widget::updateIcons() if (!hasThemeIconBug && QIcon::hasThemeIcon("qtox-" + assetSuffix)) { ico = QIcon::fromTheme("qtox-" + assetSuffix); } else { - QString color = settings.getLightTrayIcon() ? "light" : "dark"; + QString color = settings.getLightTrayIcon() ? QStringLiteral("light") : QStringLiteral("dark"); QString path = ":/img/taskbar/" + color + "/taskbar_" + assetSuffix + ".svg"; QSvgRenderer renderer(path); @@ -2484,9 +2484,9 @@ inline QIcon Widget::prepareIcon(QString path, int w, int h) { #ifdef Q_OS_LINUX - QString desktop = getenv("XDG_CURRENT_DESKTOP"); + QString desktop = QString::fromUtf8(getenv("XDG_CURRENT_DESKTOP")); if (desktop.isEmpty()) { - desktop = getenv("DESKTOP_SESSION"); + desktop = QString::fromUtf8(getenv("DESKTOP_SESSION")); } desktop = desktop.toLower(); diff --git a/test/model/friendmessagedispatcher_test.cpp b/test/model/friendmessagedispatcher_test.cpp index 80015f6925..6f265edc3e 100644 --- a/test/model/friendmessagedispatcher_test.cpp +++ b/test/model/friendmessagedispatcher_test.cpp @@ -400,7 +400,7 @@ void TestFriendMessageDispatcher::testActionMessagesSplitWithExtensions() auto reallyLongMessage = QString("a"); for (uint64_t i = 0; i < testMaxExtendedMessageSize + 50; ++i) { - reallyLongMessage += i; + reallyLongMessage += QString().number(i); } friendMessageDispatcher->sendMessage(true, reallyLongMessage); diff --git a/test/persistence/smileypack_test.cpp b/test/persistence/smileypack_test.cpp index ab0fc47b0e..6e1442c149 100644 --- a/test/persistence/smileypack_test.cpp +++ b/test/persistence/smileypack_test.cpp @@ -116,7 +116,7 @@ void TestSmileyPack::testSmilifyAsciiEmoticon() auto result = smileyPack.smileyfied(":-)"); QVERIFY(result == SmileyPack::getAsRichText(":-)")); - constexpr auto testMsg = "Some:-)Letters"; + const auto testMsg = QStringLiteral("Some:-)Letters"); result = smileyPack.smileyfied(testMsg); // Nothing has changed. Ascii smileys are only considered diff --git a/util/src/display.cpp b/util/src/display.cpp index 920e1f5f11..21ad5c41f0 100644 --- a/util/src/display.cpp +++ b/util/src/display.cpp @@ -30,5 +30,5 @@ QString getHumanReadableSize(uint64_t size) exp = std::min(static_cast(log(size) / log(1024)), static_cast(sizeof(suffix) / sizeof(suffix[0]) - 1)); } - return QString().setNum(size / pow(1024, exp), 'f', exp > 1 ? 2 : 0).append(suffix[exp]); + return QString().setNum(size / pow(1024, exp), 'f', exp > 1 ? 2 : 0).append(QString::fromUtf8(suffix[exp])); }