diff --git a/src/common/ownsql.cpp b/src/common/ownsql.cpp index 1b3c8c6437..a0669579a4 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::convert(len)) == 0; } bool SqlQuery::isSelect() diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 2c2a3e5ef7..6c394f1450 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -396,6 +396,16 @@ void Utility::crash() *a = 1; } +// Use this function to retrieve uint (often required by Qt and WIN32) from size_t +// without compiler warnings about possible truncation +uint Utility::convert(size_t &convertVar) +{ + if( convertVar > UINT_MAX ) { + throw std::bad_cast(); + } + return static_cast(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 5e1ff930eb..3842253918 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -55,6 +55,7 @@ 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 convert(size_t &convertVar); /** * Return the amount of free space available.