From bbae5c891b8807399271a655f99a3c90882a0f9e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 14 Mar 2022 10:37:39 +0100 Subject: [PATCH] QFileSystemEngine: fix potential formatting error It's not immediately clear that trashedName doesn't contain %1 or %2, in which case the subsequent .arg() would replace that instead of the intended %2. Fix by using QString::asprintf(), which doesn't perform multiple interpolation passes. Pick-to: 6.3 6.2 5.15 Change-Id: Ib6c24bfea01db4cdc80f7547c8269cce3f815158 Reviewed-by: Qt CI Bot Reviewed-by: Sona Kurazyan --- src/corelib/io/qfilesystemengine_unix.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 3baf2d20b78..ea903fa9909 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1374,10 +1374,7 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source, int counter = 0; QFile infoFile; auto makeUniqueTrashedName = [trashedName, &counter]() -> QString { - ++counter; - return QString(QLatin1String("/%1-%2")) - .arg(trashedName) - .arg(counter, 4, 10, QLatin1Char('0')); + return QString::asprintf("/%ls-%04d", qUtf16Printable(trashedName), ++counter); }; do { while (QFile::exists(trashDir.filePath(filesDir) + uniqueTrashedName))