Implemented Utility::convert function to convert size_t -> uint safely and on the fly. Often necessary for Qt and WIN32 functions. Using this will not generate compiler warnings of possible truncation. First call implemented in ownsql.cpp

Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
This commit is contained in:
Dominique Fuchs 2019-09-08 02:04:50 +02:00
parent 5ae3435fe6
commit b4dee67bf5
3 changed files with 13 additions and 2 deletions

View File

@ -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()

View File

@ -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<uint>(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

View File

@ -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.