From c50a968a1e0cd44ab2cb0725ae418b1be6b4d0e3 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 4 Jun 2020 14:09:06 +0200 Subject: [PATCH 1/2] Add more raw string literals missed previously Signed-off-by: Kevin Ottens --- .clang-tidy | 1 + .../OCContextMenu/OCContextMenuRegHandler.cpp | 10 ++++----- .../windows/OCUtil/CommunicationSocket.cpp | 2 +- src/common/filesystembase.h | 4 ++-- src/common/utility.cpp | 2 +- src/common/utility_win.cpp | 4 ++-- src/gui/navigationpanehelper.cpp | 4 ++-- .../csync/csync_tests/check_csync_exclude.cpp | 2 +- test/csync/encoding_tests/check_encoding.cpp | 22 +++++++++---------- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 311e66d9e..4c03e129d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,7 @@ Checks: '-*, cppcoreguidelines-init-variables, modernize-make-*, + modernize-raw-string-literal, modernize-redundant-void-arg, modernize-replace-*, modernize-return-braced-init-list, diff --git a/shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp b/shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp index e855ff43f..38e1d5e06 100644 --- a/shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp +++ b/shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp @@ -85,7 +85,7 @@ HRESULT OCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CL wchar_t szSubkey[MAX_PATH]; // Create the HKCR\CLSID\{} key. - hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID); + hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), LR"(CLSID\%s)", szCLSID); if (SUCCEEDED(hr)) { hr = SetHKCRRegistryKeyAndValue(szSubkey, nullptr, pszFriendlyName); @@ -94,7 +94,7 @@ HRESULT OCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CL if (SUCCEEDED(hr)) { hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), - L"CLSID\\%s\\InprocServer32", szCLSID); + LR"(CLSID\%s\InprocServer32)", szCLSID); if (SUCCEEDED(hr)) { // Set the default value of the InprocServer32 key to the @@ -123,7 +123,7 @@ HRESULT OCContextMenuRegHandler::UnregisterInprocServer(const CLSID& clsid) wchar_t szSubkey[MAX_PATH]; // Delete the HKCR\CLSID\{} key. - hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID); + hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), LR"(CLSID\%s)", szCLSID); if (SUCCEEDED(hr)) { hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey)); @@ -167,7 +167,7 @@ HRESULT OCContextMenuRegHandler::RegisterShellExtContextMenuHandler( // Create the key HKCR\\shellex\ContextMenuHandlers\{friendlyName>} hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), - L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, pszFriendlyName); + LR"(%s\shellex\ContextMenuHandlers\%s)", pszFileType, pszFriendlyName); if (SUCCEEDED(hr)) { // Set the default value of the key. @@ -208,7 +208,7 @@ HRESULT OCContextMenuRegHandler::UnregisterShellExtContextMenuHandler( // Remove the HKCR\\shellex\ContextMenuHandlers\{friendlyName} key. hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), - L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, pszFriendlyName); + LR"(%s\shellex\ContextMenuHandlers\%s)", pszFileType, pszFriendlyName); if (SUCCEEDED(hr)) { hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey)); diff --git a/shell_integration/windows/OCUtil/CommunicationSocket.cpp b/shell_integration/windows/OCUtil/CommunicationSocket.cpp index f24b30ba6..649a9a145 100644 --- a/shell_integration/windows/OCUtil/CommunicationSocket.cpp +++ b/shell_integration/windows/OCUtil/CommunicationSocket.cpp @@ -44,7 +44,7 @@ std::wstring getUserName() { std::wstring CommunicationSocket::DefaultPipePath() { - auto pipename = std::wstring(L"\\\\.\\pipe\\"); + auto pipename = std::wstring(LR"(\\.\pipe\)"); pipename += L"ownCloud-"; pipename += getUserName(); return pipename; diff --git a/src/common/filesystembase.h b/src/common/filesystembase.h index c5bed6558..08abdfcb1 100644 --- a/src/common/filesystembase.h +++ b/src/common/filesystembase.h @@ -175,10 +175,10 @@ namespace FileSystem { if( str[0] == '/' || str[0] == '\\' ) { // Don't prepend if already UNC if( !(len > 1 && (str[1] == '/' || str[1] == '\\')) ) { - longStr.append("\\\\?"); + longStr.append(R"(\\?)"); } } else { - longStr.append("\\\\?\\"); // prepend string by this four magic chars. + longStr.append(R"(\\?\)"); // prepend string by this four magic chars. } longStr += str; diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 28f507696..519bfc022 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -666,7 +666,7 @@ QByteArray Utility::conflictFileBaseName(const QByteArray &conflictName) QString Utility::sanitizeForFileName(const QString &name) { - const auto invalid = QStringLiteral("/?<>\\:*|\""); + const auto invalid = QStringLiteral(R"(/?<>\:*|")"); QString result; result.reserve(name.size()); for (const auto c : name) { diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp index 9df84e0c5..13badf599 100644 --- a/src/common/utility_win.cpp +++ b/src/common/utility_win.cpp @@ -25,7 +25,7 @@ #include #include -static const char runPathC[] = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"; +static const char runPathC[] = R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)"; namespace OCC { @@ -91,7 +91,7 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName, static inline bool hasDarkSystray_private() { if(Utility::registryGetKeyValue( HKEY_CURRENT_USER, - "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", "SystemUsesLightTheme" ) == 1) { return false; } diff --git a/src/gui/navigationpanehelper.cpp b/src/gui/navigationpanehelper.cpp index f738799d4..a95830eee 100644 --- a/src/gui/navigationpanehelper.cpp +++ b/src/gui/navigationpanehelper.cpp @@ -68,7 +68,7 @@ void NavigationPaneHelper::updateCloudStorageRegistry() #ifdef Q_OS_WIN Utility::registryWalkSubKeys( HKEY_CURRENT_USER, - QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\NameSpace"), + QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)"), [&entriesToRemove](HKEY key, const QString &subKey) { QVariant appName = Utility::registryGetKeyValue(key, subKey, QStringLiteral("ApplicationName")); if (appName.toString() == QLatin1String(APPLICATION_NAME)) { @@ -138,7 +138,7 @@ void NavigationPaneHelper::updateCloudStorageRegistry() // Step 11: Register your extension in the namespace root Utility::registrySetKeyValue(HKEY_CURRENT_USER, namespacePath, QString(), REG_SZ, title); // Step 12: Hide your extension from the Desktop - Utility::registrySetKeyValue(HKEY_CURRENT_USER, QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\NewStartPanel"), clsidStr, REG_DWORD, 0x1); + Utility::registrySetKeyValue(HKEY_CURRENT_USER, QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel)"), clsidStr, REG_DWORD, 0x1); // For us, to later be able to iterate and find our own namespace entries and associated CLSID. // Use the macro instead of the theme to make sure it matches with the uninstaller. diff --git a/test/csync/csync_tests/check_csync_exclude.cpp b/test/csync/csync_tests/check_csync_exclude.cpp index 85efea368..c052f2424 100644 --- a/test/csync/csync_tests/check_csync_exclude.cpp +++ b/test/csync/csync_tests/check_csync_exclude.cpp @@ -681,7 +681,7 @@ static void check_csync_exclude_expand_escapes(void **state) { (void)state; - QByteArray line = "keep \\' \\\" \\? \\\\ \\a \\b \\f \\n \\r \\t \\v \\z \\#"; + QByteArray line = R"(keep \' \" \? \\ \a \b \f \n \r \t \v \z \#)"; csync_exclude_expand_escapes(line); assert_true(0 == strcmp(line.constData(), "keep ' \" ? \\\\ \a \b \f \n \r \t \v \\z #")); diff --git a/test/csync/encoding_tests/check_encoding.cpp b/test/csync/encoding_tests/check_encoding.cpp index 22dc20e1e..7d3733bc6 100644 --- a/test/csync/encoding_tests/check_encoding.cpp +++ b/test/csync/encoding_tests/check_encoding.cpp @@ -116,35 +116,35 @@ static void check_long_win_path(void **state) { const char *path = "C://DATA/FILES/MUSIC/MY_MUSIC.mp3"; // check a short path - const char *exp_path = "\\\\?\\C:\\\\DATA\\FILES\\MUSIC\\MY_MUSIC.mp3"; + const char *exp_path = R"(\\?\C:\\DATA\FILES\MUSIC\MY_MUSIC.mp3)"; QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path))); assert_string_equal(new_short, exp_path); } { - const char *path = "\\\\foo\\bar/MY_MUSIC.mp3"; - const char *exp_path = "\\\\foo\\bar\\MY_MUSIC.mp3"; + const char *path = R"(\\foo\bar/MY_MUSIC.mp3)"; + const char *exp_path = R"(\\foo\bar\MY_MUSIC.mp3)"; QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path))); assert_string_equal(new_short, exp_path); } { - const char *path = "//foo\\bar/MY_MUSIC.mp3"; - const char *exp_path = "\\\\foo\\bar\\MY_MUSIC.mp3"; + const char *path = R"(//foo\bar/MY_MUSIC.mp3)"; + const char *exp_path = R"(\\foo\bar\MY_MUSIC.mp3)"; QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path))); assert_string_equal(new_short, exp_path); } { const char *path = "\\foo\\bar"; - const char *exp_path = "\\\\?\\foo\\bar"; + const char *exp_path = R"(\\?\foo\bar)"; QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path))); assert_string_equal(new_short, exp_path); } { const char *path = "/foo/bar"; - const char *exp_path = "\\\\?\\foo\\bar"; + const char *exp_path = R"(\\?\foo\bar)"; QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path))); assert_string_equal(new_short, exp_path); } @@ -153,10 +153,10 @@ static void check_long_win_path(void **state) "elonglonglonglong/flonglonglonglong/glonglonglonglong/hlonglonglonglong/ilonglonglonglong/" "jlonglonglonglong/klonglonglonglong/llonglonglonglong/mlonglonglonglong/nlonglonglonglong/" "olonglonglonglong/file.txt"; - const char *longPathConv = "\\\\?\\D:\\\\alonglonglonglong\\blonglonglonglong\\clonglonglonglong\\dlonglonglonglong\\" - "elonglonglonglong\\flonglonglonglong\\glonglonglonglong\\hlonglonglonglong\\ilonglonglonglong\\" - "jlonglonglonglong\\klonglonglonglong\\llonglonglonglong\\mlonglonglonglong\\nlonglonglonglong\\" - "olonglonglonglong\\file.txt"; + const char *longPathConv = R"(\\?\D:\\alonglonglonglong\blonglonglonglong\clonglonglonglong\dlonglonglonglong\)" + R"(elonglonglonglong\flonglonglonglong\glonglonglonglong\hlonglonglonglong\ilonglonglonglong\)" + R"(jlonglonglonglong\klonglonglonglong\llonglonglonglong\mlonglonglonglong\nlonglonglonglong\)" + R"(olonglonglonglong\file.txt)"; QByteArray new_long = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(longPath, strlen(longPath))); // printf("XXXXXXXXXXXX %s %d\n", new_long, mem_reserved); From 3e79e1861bc917f057c175aead4b4863f7f26a3d Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 4 Jun 2020 14:09:21 +0200 Subject: [PATCH 2/2] We don't really need two \ here Signed-off-by: Kevin Ottens --- src/libsync/syncengine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index dda6cbb86..5fdd070c7 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -1100,7 +1100,7 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult) // files with names that contain these. // It's important to respect the capability also for older servers -- the // version check doesn't make sense for custom servers. - invalidFilenamePattern = R"([\\:?*"<>|])"; + invalidFilenamePattern = R"([\:?*"<>|])"; } if (!invalidFilenamePattern.isEmpty()) { const QRegExp invalidFilenameRx(invalidFilenamePattern);