Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schuster <48932272+misch7@users.noreply.github.com>2019-09-16 20:08:10 +0300
committerGitHub <noreply@github.com>2019-09-16 20:08:10 +0300
commitb93fbddf05a7f8820c5e52edf35135d9ff3e6a8b (patch)
tree52ec05563edd60a20a4f1b65510c2c13c13f8823
parent44d954ade9aa3067d7de11787ded5b2d81057477 (diff)
parentb40e3e7b4e021bfef5a3762f98378295e77d0bdd (diff)
Merge pull request #1409 from DominiqueFuchs/msvc-warn-audit
Review of msvc/gcc warnings -> code cleanup, prevention of implicit casts, variadic macros
-rw-r--r--CMakeLists.txt12
-rw-r--r--cmake/modules/Warnings.cmake6
-rw-r--r--shell_integration/windows/OCContextMenu/OCContextMenu.cpp2
-rw-r--r--shell_integration/windows/OCContextMenu/targetver.h6
-rw-r--r--shell_integration/windows/OCOverlays/stdafx.h6
-rw-r--r--shell_integration/windows/OCUtil/stdafx.h6
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/common/asserts.h29
-rw-r--r--src/common/c_jhash.h3
-rw-r--r--src/common/ownsql.cpp4
-rw-r--r--src/common/syncjournaldb.h1
-rw-r--r--src/common/utility.cpp20
-rw-r--r--src/common/utility.h6
-rw-r--r--src/common/utility_win.cpp42
-rw-r--r--src/csync/csync_exclude.cpp2
-rw-r--r--src/csync/csync_update.cpp3
-rw-r--r--src/csync/std/c_utf8.cpp10
-rw-r--r--src/csync/vio/csync_vio_local_win.cpp2
-rw-r--r--src/gui/activityitemdelegate.cpp23
-rw-r--r--src/gui/creds/webflowcredentials.cpp4
-rw-r--r--src/gui/folder.cpp7
-rw-r--r--src/gui/folderman.cpp2
-rw-r--r--src/gui/folderwatcher_win.cpp10
-rw-r--r--src/gui/generalsettings.cpp15
-rw-r--r--src/gui/openfilemanager.cpp16
-rw-r--r--src/gui/settingsdialog.cpp2
-rw-r--r--src/gui/sharelinkwidget.cpp1
-rw-r--r--src/gui/wizard/slideshow.cpp6
-rw-r--r--src/gui/wizard/webview.cpp3
-rw-r--r--src/libsync/clientsideencryption.cpp11
-rw-r--r--src/libsync/configfile.cpp12
-rw-r--r--src/libsync/propagatedownload.cpp5
32 files changed, 203 insertions, 78 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f1d07eea2..f8e92e250 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -203,8 +203,16 @@ if( WIN32 )
add_definitions( -D__USE_MINGW_ANSI_STDIO=1 )
add_definitions( -DNOMINMAX )
# Get APIs from from Vista onwards.
-add_definitions( -D_WIN32_WINNT=0x0600)
-add_definitions( -DWINVER=0x0600)
+add_definitions( -D_WIN32_WINNT=0x0601 )
+add_definitions( -DWINVER=0x0601 )
+ if( MSVC )
+ # Use automatic overload for suitable CRT safe-functions
+ # See https://docs.microsoft.com/de-de/cpp/c-runtime-library/security-features-in-the-crt?view=vs-2019
+ add_definitions( -D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1 )
+ # Also: Disable compiler warnings because we don't use Windows CRT safe-functions explicitly and don't intend to
+ # as this is a pure cross-platform source the only alternative would be a ton of ifdefs with calls to the _s version
+ add_definitions( -D_CRT_SECURE_NO_WARNINGS )
+ endif( MSVC )
endif( WIN32 )
if (APPLE)
diff --git a/cmake/modules/Warnings.cmake b/cmake/modules/Warnings.cmake
index d4f7c910a..fff28ca7f 100644
--- a/cmake/modules/Warnings.cmake
+++ b/cmake/modules/Warnings.cmake
@@ -3,7 +3,11 @@
# For details see the accompanying COPYING* file.
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long -Wno-gnu-zero-variadic-macro-arguments")
+
+ # Use this only for Clang
+ if (CMAKE_CXX_COMPILER MATCHES "Clang")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long -Wno-gnu-zero-variadic-macro-arguments")
+ endif()
# Fix sqlite compilation on macOS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-incompatible-pointer-types-discards-qualifiers")
diff --git a/shell_integration/windows/OCContextMenu/OCContextMenu.cpp b/shell_integration/windows/OCContextMenu/OCContextMenu.cpp
index 9356187fe..582783f48 100644
--- a/shell_integration/windows/OCContextMenu/OCContextMenu.cpp
+++ b/shell_integration/windows/OCContextMenu/OCContextMenu.cpp
@@ -89,7 +89,7 @@ IFACEMETHODIMP OCContextMenu::Initialize(
HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal));
if (hDrop) {
UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
- for (int i = 0; i < nFiles; ++i) {
+ for (UINT i = 0; i < nFiles; ++i) {
// Get the path of the file.
wchar_t buffer[MAX_PATH];
diff --git a/shell_integration/windows/OCContextMenu/targetver.h b/shell_integration/windows/OCContextMenu/targetver.h
index ce2bc7493..e233d3572 100644
--- a/shell_integration/windows/OCContextMenu/targetver.h
+++ b/shell_integration/windows/OCContextMenu/targetver.h
@@ -5,6 +5,8 @@
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
-#define WINVER 0x0501
-#define _WIN32_WINNT 0x0501
+// Note: Here was a #define for windows target version
+// e.g. WINVER / _WIN32_WINNT, see https://devblogs.microsoft.com/oldnewthing/20070411-00/?p=27283
+// Unnecessary because we define both in desktop/CMakeLists.txt
+
#include <SDKDDKVer.h>
diff --git a/shell_integration/windows/OCOverlays/stdafx.h b/shell_integration/windows/OCOverlays/stdafx.h
index 3d94fc641..5eacb4552 100644
--- a/shell_integration/windows/OCOverlays/stdafx.h
+++ b/shell_integration/windows/OCOverlays/stdafx.h
@@ -13,8 +13,10 @@
*/
#define WIN32_LEAN_AND_MEAN
-#define WINVER 0x0501
-#define _WIN32_WINNT 0x0501
+
+// Note: Here was a #define for windows target version
+// e.g. WINVER / _WIN32_WINNT, see https://devblogs.microsoft.com/oldnewthing/20070411-00/?p=27283
+// Unnecessary because we define both in desktop/CMakeLists.txt
#include "CommunicationSocket.h"
#include "RegistryUtil.h"
diff --git a/shell_integration/windows/OCUtil/stdafx.h b/shell_integration/windows/OCUtil/stdafx.h
index e46161544..532ea3e54 100644
--- a/shell_integration/windows/OCUtil/stdafx.h
+++ b/shell_integration/windows/OCUtil/stdafx.h
@@ -1,7 +1,9 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
-#define WINVER 0x0501
-#define _WIN32_WINNT 0x0501
+
+// Note: Here was a #define for windows target version
+// e.g. WINVER / _WIN32_WINNT, see https://devblogs.microsoft.com/oldnewthing/20070411-00/?p=27283
+// Unnecessary because we define both in desktop/CMakeLists.txt
#include <windows.h>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e14c97e84..68952605a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -33,8 +33,8 @@ endif()
if(WIN32)
# Enable DEP & ASLR
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /nxcompat /dynamicbase")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /nxcompat /dynamicbase")
elseif(UNIX AND NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now")
diff --git a/src/common/asserts.h b/src/common/asserts.h
index e96e57bb9..38440ce1b 100644
--- a/src/common/asserts.h
+++ b/src/common/asserts.h
@@ -11,43 +11,50 @@
// For overloading macros by argument count
// See stackoverflow.com/questions/16683146/can-macros-be-overloaded-by-number-of-arguments
-#define OC_ASSERT_CAT(A, B) A##B
-#define OC_ASSERT_SELECT(NAME, NUM) OC_ASSERT_CAT(NAME##_, NUM)
+// Bugfix 08/09/2019: Broken arg expansion led to always collapsing to 1 arg (XXXX_1 overload result)
+// See also: https://stackoverflow.com/questions/9183993/msvc-variadic-macro-expansion
+#define OC_ASSERT_GLUE(x, y) x y
+
#define OC_ASSERT_GET_COUNT(_1, _2, _3, COUNT, ...) COUNT
-#define OC_ASSERT_VA_SIZE(...) OC_ASSERT_GET_COUNT(__VA_ARGS__, 3, 2, 1, 0)
+#define OC_ASSERT_EXPAND_ARGS(args) OC_ASSERT_GET_COUNT args
+#define OC_ASSERT_VA_SIZE(...) OC_ASSERT_EXPAND_ARGS((__VA_ARGS__, 3, 2, 1, 0))
+
+#define OC_ASSERT_SELECT2(NAME, COUNT) NAME##COUNT
+#define OC_ASSERT_SELECT1(NAME, COUNT) OC_ASSERT_SELECT2(NAME, COUNT)
+#define OC_ASSERT_SELECT(NAME, COUNT) OC_ASSERT_SELECT1(NAME, COUNT)
-#define OC_ASSERT_OVERLOAD(NAME, ...) OC_ASSERT_SELECT(NAME, OC_ASSERT_VA_SIZE(__VA_ARGS__)) \
- (__VA_ARGS__)
+#define OC_ASSERT_OVERLOAD(NAME, ...) OC_ASSERT_GLUE(OC_ASSERT_SELECT(NAME, OC_ASSERT_VA_SIZE(__VA_ARGS__)), \
+ (__VA_ARGS__))
// Default assert: If the condition is false in debug builds, terminate.
//
// Prints a message on failure, even in release builds.
-#define ASSERT(...) OC_ASSERT_OVERLOAD(ASSERT, __VA_ARGS__)
-#define ASSERT_1(cond) \
+#define ASSERT1(cond) \
if (!(cond)) { \
OC_ASSERT_MSG("ASSERT: \"%s\" in file %s, line %d", #cond, __FILE__, __LINE__); \
} else { \
}
-#define ASSERT_2(cond, message) \
+#define ASSERT2(cond, message) \
if (!(cond)) { \
OC_ASSERT_MSG("ASSERT: \"%s\" in file %s, line %d with message: %s", #cond, __FILE__, __LINE__, message); \
} else { \
}
+#define ASSERT(...) OC_ASSERT_OVERLOAD(ASSERT, __VA_ARGS__)
// Enforce condition to be true, even in release builds.
//
// Prints 'message' and aborts execution if 'cond' is false.
-#define ENFORCE(...) OC_ASSERT_OVERLOAD(ENFORCE, __VA_ARGS__)
-#define ENFORCE_1(cond) \
+#define ENFORCE1(cond) \
if (!(cond)) { \
qFatal("ENFORCE: \"%s\" in file %s, line %d", #cond, __FILE__, __LINE__); \
} else { \
}
-#define ENFORCE_2(cond, message) \
+#define ENFORCE2(cond, message) \
if (!(cond)) { \
qFatal("ENFORCE: \"%s\" in file %s, line %d with message: %s", #cond, __FILE__, __LINE__, message); \
} else { \
}
+#define ENFORCE(...) OC_ASSERT_OVERLOAD(ENFORCE, __VA_ARGS__)
// An assert that is only present in debug builds: typically used for
// asserts that are too expensive for release mode.
diff --git a/src/common/c_jhash.h b/src/common/c_jhash.h
index cd1549d7e..97decf998 100644
--- a/src/common/c_jhash.h
+++ b/src/common/c_jhash.h
@@ -207,7 +207,10 @@ static inline uint64_t c_jhash64(const uint8_t *k, uint64_t length, uint64_t int
/* handle the last 23 bytes */
c += length;
switch(len) {
+// pragma only for GCC (and clang continues to pretend to be it by defining __GNUC__)
+#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
case 23: c+=((uint64_t)k[22]<<56);
case 22: c+=((uint64_t)k[21]<<48);
case 21: c+=((uint64_t)k[20]<<40);
diff --git a/src/common/ownsql.cpp b/src/common/ownsql.cpp
index 1b3c8c643..b82808d86 100644
--- a/src/common/ownsql.cpp
+++ b/src/common/ownsql.cpp
@@ -281,8 +281,8 @@ int SqlQuery::prepare(const QByteArray &sql, bool allow_failure)
*/
static bool startsWithInsensitive(const QByteArray &a, const char *b)
{
- int len = strlen(b);
- return a.size() >= len && qstrnicmp(a.constData(), b, len) == 0;
+ size_t len = strlen(b);
+ return a.size() >= len && qstrnicmp(a.constData(), b, Utility::convertSizeToUint(len)) == 0;
}
bool SqlQuery::isSelect()
diff --git a/src/common/syncjournaldb.h b/src/common/syncjournaldb.h
index 6ad04b097..d8ebeab75 100644
--- a/src/common/syncjournaldb.h
+++ b/src/common/syncjournaldb.h
@@ -103,6 +103,7 @@ public:
: _chunk(0)
, _transferid(0)
, _size(0)
+ , _modtime(0)
, _errorCount(0)
, _valid(false)
{
diff --git a/src/common/utility.cpp b/src/common/utility.cpp
index 2c2a3e5ef..c0a22177f 100644
--- a/src/common/utility.cpp
+++ b/src/common/utility.cpp
@@ -396,6 +396,26 @@ void Utility::crash()
*a = 1;
}
+// Use this functions to retrieve uint/int (often required by Qt and WIN32) from size_t
+// without compiler warnings about possible truncation
+uint Utility::convertSizeToUint(size_t &convertVar)
+{
+ if( convertVar > UINT_MAX ) {
+ //throw std::bad_cast();
+ convertVar = UINT_MAX; // intentionally default to wrong value here to not crash: exception handling TBD
+ }
+ return static_cast<uint>(convertVar);
+}
+
+uint Utility::convertSizeToInt(size_t &convertVar)
+{
+ if( convertVar > INT_MAX ) {
+ //throw std::bad_cast();
+ convertVar = INT_MAX; // intentionally default to wrong value here to not crash: exception handling TBD
+ }
+ return static_cast<int>(convertVar);
+}
+
// read the output of the owncloud --version command from the owncloud
// version that is on disk. This works for most versions of the client,
// because clients that do not yet know the --version flag return the
diff --git a/src/common/utility.h b/src/common/utility.h
index 5e1ff930e..803f690c2 100644
--- a/src/common/utility.h
+++ b/src/common/utility.h
@@ -55,6 +55,12 @@ namespace Utility {
OCSYNC_EXPORT QByteArray userAgentString();
OCSYNC_EXPORT bool hasLaunchOnStartup(const QString &appName);
OCSYNC_EXPORT void setLaunchOnStartup(const QString &appName, const QString &guiName, bool launch);
+ OCSYNC_EXPORT uint convertSizeToUint(size_t &convertVar);
+ OCSYNC_EXPORT uint convertSizeToInt(size_t &convertVar);
+
+#ifdef Q_OS_WIN
+ OCSYNC_EXPORT DWORD convertSizeToDWORD(size_t &convertVar);
+#endif
/**
* Return the amount of free space available.
diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp
index 3706a4605..3a8c16fff 100644
--- a/src/common/utility_win.cpp
+++ b/src/common/utility_win.cpp
@@ -90,32 +90,13 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName,
// TODO: Right now only detection on toggle/startup, not when windows theme is switched while nextcloud is running
static inline bool hasDarkSystray_private()
{
- bool hasDarkSystray = true;
- // Open registry key first, continue only on success (may be legitimately absent in earlier windows versions)
- HKEY hKey;
- LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_READ, &hKey);
-
- // classical windows function - preserve buff size for DWORD, call ExW version, store regkey value in nResult
- if (lRes == ERROR_SUCCESS) {
- DWORD dwBufferSize(sizeof(DWORD));
- DWORD nResult(0);
-
- // https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
- LONG nError = ::RegQueryValueExW(hKey,
- L"SystemUsesLightTheme",
- NULL,
- NULL,
- reinterpret_cast<LPBYTE>(&nResult),
- &dwBufferSize);
-
- // if RegQuery returned no error and light theme was found, change systray return value
- if (nError == ERROR_SUCCESS && nResult == 1)
- hasDarkSystray = false;
-
- return hasDarkSystray;
- } else {
- // fallback to true if regkey could not be determined
- return hasDarkSystray;
+ if(Utility::registryGetKeyValue( HKEY_CURRENT_USER,
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
+ "SystemUsesLightTheme" ) == 1) {
+ return false;
+ }
+ else {
+ return true;
}
}
@@ -283,4 +264,13 @@ bool Utility::registryWalkSubKeys(HKEY hRootKey, const QString &subKey, const st
return retCode != ERROR_NO_MORE_ITEMS;
}
+DWORD Utility::convertSizeToDWORD(size_t &convertVar)
+{
+ if( convertVar > UINT_MAX ) {
+ //throw std::bad_cast();
+ convertVar = UINT_MAX; // intentionally default to wrong value here to not crash: exception handling TBD
+ }
+ return static_cast<DWORD>(convertVar);
+}
+
} // namespace OCC
diff --git a/src/csync/csync_exclude.cpp b/src/csync/csync_exclude.cpp
index 9a4f196ed..32b88616c 100644
--- a/src/csync/csync_exclude.cpp
+++ b/src/csync/csync_exclude.cpp
@@ -73,7 +73,7 @@ static void csync_exclude_expand_escapes(QByteArray &input)
line[o++] = line[i];
}
}
- input.resize(o);
+ input.resize(OCC::Utility::convertSizeToUint(o));
}
// See http://support.microsoft.com/kb/74496 and
diff --git a/src/csync/csync_update.cpp b/src/csync/csync_update.cpp
index ecea21cae..45a65f219 100644
--- a/src/csync/csync_update.cpp
+++ b/src/csync/csync_update.cpp
@@ -724,7 +724,8 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
if (ctx->current == LOCAL_REPLICA) {
ASSERT(dirent->path.startsWith(ctx->local.uri)); // path is relative to uri
// "len + 1" to include the slash in-between.
- dirent->path = dirent->path.mid(strlen(ctx->local.uri) + 1);
+ size_t uriLength = strlen(ctx->local.uri);
+ dirent->path = dirent->path.mid(OCC::Utility::convertSizeToInt(uriLength) + 1);
}
previous_fs = ctx->current_fs;
diff --git a/src/csync/std/c_utf8.cpp b/src/csync/std/c_utf8.cpp
index 2f862b5ce..778486e8b 100644
--- a/src/csync/std/c_utf8.cpp
+++ b/src/csync/std/c_utf8.cpp
@@ -38,6 +38,7 @@
#include "c_alloc.h"
#include "c_string.h"
#include "common/filesystembase.h"
+#include "common/utility.h"
/* Convert a locale String to UTF8 */
QByteArray c_utf8_from_locale(const mbchar_t *wstr)
@@ -52,10 +53,10 @@ QByteArray c_utf8_from_locale(const mbchar_t *wstr)
size_t len;
len = wcslen(wstr);
/* Call once to get the required size. */
- size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, len, NULL, 0, NULL, NULL);
+ size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, OCC::Utility::convertSizeToInt(len), NULL, 0, NULL, NULL);
if (size_needed > 0) {
dst.resize(size_needed);
- WideCharToMultiByte(CP_UTF8, 0, wstr, len, dst.data(), size_needed, NULL, NULL);
+ WideCharToMultiByte(CP_UTF8, 0, wstr, OCC::Utility::convertSizeToInt(len), dst.data(), size_needed, NULL, NULL);
}
return dst;
#else
@@ -95,7 +96,7 @@ mbchar_t* c_utf8_string_to_locale(const char *str)
int size_needed;
len = strlen(str);
- size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0);
+ size_needed = MultiByteToWideChar(CP_UTF8, 0, str, OCC::Utility::convertSizeToInt(len), NULL, 0);
if (size_needed > 0) {
int size_char = (size_needed + 1) * sizeof(mbchar_t);
dst = (mbchar_t*)c_malloc(size_char);
@@ -114,7 +115,8 @@ mbchar_t* c_utf8_string_to_locale(const char *str)
return NULL;
} else {
#ifdef _WIN32
- QByteArray unc_str = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(str, strlen(str)));
+ size_t strLength = strlen(str);
+ QByteArray unc_str = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(str, OCC::Utility::convertSizeToInt(strLength)));
mbchar_t *dst = c_utf8_string_to_locale(unc_str);
return dst;
#else
diff --git a/src/csync/vio/csync_vio_local_win.cpp b/src/csync/vio/csync_vio_local_win.cpp
index 9ec585a43..1c8e05920 100644
--- a/src/csync/vio/csync_vio_local_win.cpp
+++ b/src/csync/vio/csync_vio_local_win.cpp
@@ -57,7 +57,7 @@ csync_vio_handle_t *csync_vio_local_opendir(const char *name) {
handle = (dhandle_t*)c_malloc(sizeof(dhandle_t));
// the file wildcard has to be attached
- int len_name = strlen(name);
+ size_t len_name = strlen(name);
if( len_name ) {
char *h = NULL;
diff --git a/src/gui/activityitemdelegate.cpp b/src/gui/activityitemdelegate.cpp
index 7d7137442..1d49af7d7 100644
--- a/src/gui/activityitemdelegate.cpp
+++ b/src/gui/activityitemdelegate.cpp
@@ -26,6 +26,8 @@
#include <QPainter>
#include <QApplication>
+#define HASQT5_11 (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
+
namespace OCC {
int ActivityItemDelegate::_iconHeight = 0;
@@ -106,7 +108,11 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
// subject text rect
QRect actionTextBox = actionIconRect;
+#if (HASQT5_11)
+ int actionTextBoxWidth = fm.horizontalAdvance(actionText);
+#else
int actionTextBoxWidth = fm.width(actionText);
+#endif
actionTextBox.setTop(option.rect.top() + margin + offset/2);
actionTextBox.setHeight(fm.height());
actionTextBox.setLeft(actionIconRect.right() + margin);
@@ -114,7 +120,11 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
// message text rect
QRect messageTextBox = actionTextBox;
+#if (HASQT5_11)
+ int messageTextWidth = fm.horizontalAdvance(messageText);
+#else
int messageTextWidth = fm.width(messageText);
+#endif
int messageTextTop = option.rect.top() + fm.height() + margin;
if(actionText.isEmpty()) messageTextTop = option.rect.top() + margin + offset/2;
messageTextBox.setTop(messageTextTop);
@@ -129,7 +139,11 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
// time box rect
QRect timeBox = messageTextBox;
QString timeStr = tr("%1").arg(timeText);
+#if (HASQT5_11)
+ int timeTextWidth = fm.horizontalAdvance(timeStr);
+#else
int timeTextWidth = fm.width(timeStr);
+#endif
int timeTop = option.rect.top() + fm.height() + fm.height() + margin + offset/2;
if(messageText.isEmpty() || actionText.isEmpty())
timeTop = option.rect.top() + fm.height() + margin;
@@ -180,7 +194,11 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
if(objectType == _remote_share) primaryButton.text = tr("Accept");
if(objectType == _call) primaryButton.text = tr("Join");
+#if (HASQT5_11)
+ primaryButton.rect.setLeft(left - margin * 2 - fm.horizontalAdvance(primaryButton.text));
+#else
primaryButton.rect.setLeft(left - margin * 2 - fm.width(primaryButton.text));
+#endif
// save info to be able to filter mouse clicks
_buttonHeight = buttonSize;
@@ -196,7 +214,12 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
// Primary button will be 'open browser'
primaryButton.text = tr("Open Browser");
+
+#if (HASQT5_11)
+ primaryButton.rect.setLeft(left - margin * 2 - fm.horizontalAdvance(primaryButton.text));
+#else
primaryButton.rect.setLeft(left - margin * 2 - fm.width(primaryButton.text));
+#endif
// save info to be able to filter mouse clicks
_buttonHeight = buttonSize;
diff --git a/src/gui/creds/webflowcredentials.cpp b/src/gui/creds/webflowcredentials.cpp
index b34e6e054..ce3a1264e 100644
--- a/src/gui/creds/webflowcredentials.cpp
+++ b/src/gui/creds/webflowcredentials.cpp
@@ -372,7 +372,7 @@ void WebFlowCredentials::forgetSensitiveData() {
invalidateToken();
/* IMPORTANT
- /* TODO: For "Log out" & "Remove account": Remove client CA certs and KEY!
+ * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY!
*
* Disabled as long as selecting another cert is not supported by the UI.
*
@@ -539,7 +539,7 @@ void WebFlowCredentials::slotReadClientCaCertsPEMJobDone(QKeychain::Job *incomin
return;
} else {
if (readJob->error() != QKeychain::Error::EntryNotFound ||
- (readJob->error() == QKeychain::Error::EntryNotFound) && _clientSslCaCertificates.count() == 0) {
+ ((readJob->error() == QKeychain::Error::EntryNotFound) && _clientSslCaCertificates.count() == 0)) {
qCWarning(lcWebFlowCredentials) << "Unable to read client CA cert slot " << QString::number(_clientSslCaCertificates.count()) << readJob->errorString();
}
}
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index f5aedacf0..9585202f5 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -417,6 +417,13 @@ void Folder::createGuiLog(const QString &filename, LogStatus status, int count,
text = tr("%1 could not be synced due to an error. See the log for details.").arg(file);
}
break;
+ case LogStatusFileLocked:
+ if (count > 1) {
+ text = tr("%1 and %n other file(s) are currently locked.", "", count -1).arg(file);
+ } else {
+ text = tr("%1 is currently locked.").arg(file);
+ }
+ break;
}
if (!text.isEmpty()) {
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index 38b461a3e..ec708d9b7 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -562,7 +562,7 @@ void FolderMan::slotEtagJobDestroyed(QObject * /*o*/)
void FolderMan::slotRunOneEtagJob()
{
if (_currentEtagJob.isNull()) {
- Folder *folder;
+ Folder *folder = nullptr;
foreach (Folder *f, _folderMap) {
if (f->etagJob()) {
// Caveat: always grabs the first folder with a job, but we think this is Ok for now and avoids us having a seperate queue.
diff --git a/src/gui/folderwatcher_win.cpp b/src/gui/folderwatcher_win.cpp
index 4f963fbe2..4adc6cd6c 100644
--- a/src/gui/folderwatcher_win.cpp
+++ b/src/gui/folderwatcher_win.cpp
@@ -19,6 +19,8 @@
#include "folderwatcher.h"
#include "folderwatcher_win.h"
+#include "common/utility.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <tchar.h>
@@ -52,7 +54,7 @@ void WatcherThread::watchChanges(size_t fileNotifyBufferSize,
// QVarLengthArray ensures the stack-buffer is aligned like double and qint64.
QVarLengthArray<char, 4096 * 10> fileNotifyBuffer;
- fileNotifyBuffer.resize(fileNotifyBufferSize);
+ fileNotifyBuffer.resize(OCC::Utility::convertSizeToInt(fileNotifyBufferSize));
const size_t fileNameBufferSize = 4096;
TCHAR fileNameBuffer[fileNameBufferSize];
@@ -66,7 +68,7 @@ void WatcherThread::watchChanges(size_t fileNotifyBufferSize,
DWORD dwBytesReturned = 0;
SecureZeroMemory(pFileNotifyBuffer, fileNotifyBufferSize);
if (!ReadDirectoryChangesW(_directory, (LPVOID)pFileNotifyBuffer,
- fileNotifyBufferSize, true,
+ OCC::Utility::convertSizeToDWORD(fileNotifyBufferSize), true,
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE,
&dwBytesReturned,
&overlapped,
@@ -113,7 +115,7 @@ void WatcherThread::watchChanges(size_t fileNotifyBufferSize,
FILE_NOTIFY_INFORMATION *curEntry = pFileNotifyBuffer;
forever {
size_t len = curEntry->FileNameLength / 2;
- QString file = _path + "\\" + QString::fromWCharArray(curEntry->FileName, len);
+ QString file = _path + "\\" + QString::fromWCharArray(curEntry->FileName, OCC::Utility::convertSizeToInt(len));
// Unless the file was removed or renamed, get its full long name
// TODO: We could still try expanding the path in the tricky cases...
@@ -122,7 +124,7 @@ void WatcherThread::watchChanges(size_t fileNotifyBufferSize,
&& curEntry->Action != FILE_ACTION_RENAMED_OLD_NAME) {
size_t longNameSize = GetLongPathNameW(reinterpret_cast<LPCWSTR>(file.utf16()), fileNameBuffer, fileNameBufferSize);
if (longNameSize > 0) {
- longfile = QString::fromUtf16(reinterpret_cast<const ushort *>(fileNameBuffer), longNameSize);
+ longfile = QString::fromUtf16(reinterpret_cast<const ushort *>(fileNameBuffer), OCC::Utility::convertSizeToInt(longNameSize));
} else {
qCWarning(lcFolderWatcher) << "Error converting file name to full length, keeping original name.";
}
diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp
index dd4235834..62381d36d 100644
--- a/src/gui/generalsettings.cpp
+++ b/src/gui/generalsettings.cpp
@@ -26,6 +26,7 @@
#include "updater/updater.h"
#include "updater/ocupdater.h"
#include "ignorelisteditor.h"
+#include "common/utility.h"
#include "config.h"
@@ -35,6 +36,12 @@
#include <QDir>
#include <QScopedValueRollback>
+#define QTLEGACY (QT_VERSION < QT_VERSION_CHECK(5,9,0))
+
+#if !(QTLEGACY)
+#include <QOperatingSystemVersion>
+#endif
+
namespace OCC {
GeneralSettings::GeneralSettings(QWidget *parent)
@@ -79,9 +86,13 @@ GeneralSettings::GeneralSettings(QWidget *parent)
// Hide on non-Windows, or WindowsVersion < 10.
// The condition should match the default value of ConfigFile::showInExplorerNavigationPane.
#ifdef Q_OS_WIN
- if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS10)
+ #if QTLEGACY
+ if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS10)
+ #else
+ if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows10)
+ #endif
+ _ui->showInExplorerNavigationPaneCheckBox->setVisible(false);
#endif
- _ui->showInExplorerNavigationPaneCheckBox->setVisible(false);
/* Set the left contents margin of the layout to zero to make the checkboxes
* align properly vertically , fixes bug #3758
diff --git a/src/gui/openfilemanager.cpp b/src/gui/openfilemanager.cpp
index e466bdc49..c186fc4fe 100644
--- a/src/gui/openfilemanager.cpp
+++ b/src/gui/openfilemanager.cpp
@@ -22,6 +22,12 @@
#include <QDesktopServices>
#include <QApplication>
+#define QTLEGACY (QT_VERSION < QT_VERSION_CHECK(5,9,0))
+
+#if !(QTLEGACY)
+#include <QOperatingSystemVersion>
+#endif
+
namespace OCC {
// according to the QStandardDir impl from Qt5
@@ -89,10 +95,14 @@ void showInFileManager(const QString &localPath)
{
if (Utility::isWindows()) {
#ifdef Q_OS_WIN
- if (QSysInfo::windowsVersion() <= QSysInfo::WV_2003) {
- return;
- }
+ #if QTLEGACY
+ if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS10)
+ #else
+ if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows7)
+ #endif
+ return;
#endif
+
QString explorer = "explorer.exe "; // FIXME: we trust it's in PATH
QFileInfo fi(localPath);
diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp
index 2b8b98a67..e91b96853 100644
--- a/src/gui/settingsdialog.cpp
+++ b/src/gui/settingsdialog.cpp
@@ -48,7 +48,7 @@ const char TOOLBAR_CSS[] =
"QToolBar QToolBarExtension { padding:0; } "
"QToolBar QToolButton:checked { background: %3; color: %4; }";
-static const float buttonSizeRatio = 1.618; // golden ratio
+static const float buttonSizeRatio = 1.618f; // golden ratio
}
diff --git a/src/gui/sharelinkwidget.cpp b/src/gui/sharelinkwidget.cpp
index a09e2c4e3..51f3890fb 100644
--- a/src/gui/sharelinkwidget.cpp
+++ b/src/gui/sharelinkwidget.cpp
@@ -277,6 +277,7 @@ void ShareLinkWidget::slotCreatePassword()
void ShareLinkWidget::slotCreateShareLink(bool clicked)
{
+ Q_UNUSED(clicked);
slotToggleAnimation(true);
emit createLinkShare();
}
diff --git a/src/gui/wizard/slideshow.cpp b/src/gui/wizard/slideshow.cpp
index 01ea9eaca..994e4d9ca 100644
--- a/src/gui/wizard/slideshow.cpp
+++ b/src/gui/wizard/slideshow.cpp
@@ -19,6 +19,8 @@
#include <QStyle>
#include <QStyleHints>
+#define HASQT5_11 (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
+
namespace OCC {
static const int Spacing = 6;
@@ -88,7 +90,11 @@ QSize SlideShow::sizeHint() const
QFontMetrics fm = fontMetrics();
QSize labelSize(0, fm.height());
for (const QString &label : _labels) {
+#if (HASQT5_11)
+ labelSize.setWidth(std::max(fm.horizontalAdvance(label), labelSize.width()));
+#else
labelSize.setWidth(std::max(fm.width(label), labelSize.width()));
+#endif
}
QSize pixmapSize;
for (const QPixmap &pixmap : _pixmaps) {
diff --git a/src/gui/wizard/webview.cpp b/src/gui/wizard/webview.cpp
index f0e5e2159..7b0bd17ed 100644
--- a/src/gui/wizard/webview.cpp
+++ b/src/gui/wizard/webview.cpp
@@ -181,6 +181,7 @@ WebEnginePage::WebEnginePage(QWebEngineProfile *profile, QObject* parent) : QWeb
}
QWebEnginePage * WebEnginePage::createWindow(QWebEnginePage::WebWindowType type) {
+ Q_UNUSED(type);
ExternalWebEnginePage *view = new ExternalWebEnginePage(this->profile());
return view;
}
@@ -222,6 +223,8 @@ ExternalWebEnginePage::ExternalWebEnginePage(QWebEngineProfile *profile, QObject
bool ExternalWebEnginePage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
+ Q_UNUSED(type);
+ Q_UNUSED(isMainFrame);
QDesktopServices::openUrl(url);
return false;
}
diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp
index 5c5f23c9e..59816dd12 100644
--- a/src/libsync/clientsideencryption.cpp
+++ b/src/libsync/clientsideencryption.cpp
@@ -32,6 +32,7 @@
#include <QUuid>
#include <keychain.h>
+#include "common/utility.h"
#include "wordlist.h"
@@ -62,11 +63,11 @@ namespace {
namespace {
QByteArray BIO2ByteArray(BIO *b) {
- int pending = BIO_ctrl_pending(b);
+ size_t pending = BIO_ctrl_pending(b);
char *tmp = (char *)calloc(pending+1, sizeof(char));
- BIO_read(b, tmp, pending);
+ BIO_read(b, tmp, OCC::Utility::convertSizeToInt(pending));
- QByteArray res(tmp, pending);
+ QByteArray res(tmp, OCC::Utility::convertSizeToInt(pending));
free(tmp);
return res;
@@ -549,7 +550,7 @@ QByteArray decryptStringAsymmetric(EVP_PKEY *privateKey, const QByteArray& data)
}
const auto ret = std::string((char*) out, outlen);
- QByteArray raw((const char*) out, outlen);
+ QByteArray raw((const char*) out, OCC::Utility::convertSizeToInt(outlen));
qCInfo(lcCse()) << raw;
return raw;
}
@@ -603,7 +604,7 @@ QByteArray encryptStringAsymmetric(EVP_PKEY *publicKey, const QByteArray& data)
}
// Transform the encrypted data into base64.
- QByteArray raw((const char*) out, outLen);
+ QByteArray raw((const char*) out, OCC::Utility::convertSizeToInt(outLen));
qCInfo(lcCse()) << raw.toBase64();
return raw.toBase64();
}
diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp
index 4a71dc9a9..f494f14ea 100644
--- a/src/libsync/configfile.cpp
+++ b/src/libsync/configfile.cpp
@@ -37,6 +37,12 @@
#include <QNetworkProxy>
#include <QStandardPaths>
+#define QTLEGACY (QT_VERSION < QT_VERSION_CHECK(5,9,0))
+
+#if !(QTLEGACY)
+#include <QOperatingSystemVersion>
+#endif
+
#define DEFAULT_REMOTE_POLL_INTERVAL 5000 // default remote poll time in milliseconds
#define DEFAULT_MAX_LOG_LINES 20000
@@ -174,7 +180,11 @@ bool ConfigFile::showInExplorerNavigationPane() const
{
const bool defaultValue =
#ifdef Q_OS_WIN
- QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS10
+ #if QTLEGACY
+ (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS10);
+ #else
+ QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10;
+ #endif
#else
false
#endif
diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp
index da2d88b82..a0d1bd6bc 100644
--- a/src/libsync/propagatedownload.cpp
+++ b/src/libsync/propagatedownload.cpp
@@ -798,7 +798,10 @@ namespace { // Anonymous namespace for the recall feature
static void preserveGroupOwnership(const QString &fileName, const QFileInfo &fi)
{
#ifdef Q_OS_UNIX
- chown(fileName.toLocal8Bit().constData(), -1, fi.groupId());
+ int chownErr = chown(fileName.toLocal8Bit().constData(), -1, fi.groupId());
+ if (chownErr) {
+ // TODO: Error handling!
+ }
#else
Q_UNUSED(fileName);
Q_UNUSED(fi);