Fix compiler warnings on windows.

Ignore some warnings inside 3rd party code and fix a lot of conversion
warnings.

Change-Id: I909f2f31a4639015bf7dd028d2d435ff1d1167bc
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
David Schulz
2016-04-20 09:33:21 +02:00
parent 89c2b2cd32
commit cc04b84917
13 changed files with 50 additions and 37 deletions

View File

@@ -36,7 +36,7 @@ win32 {
win32-msvc* { win32-msvc* {
QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHs QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHs
QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250 QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250 -wd4297 -wd4267 -wd4334
DEFINES += BOTAN_BUILD_COMPILER_IS_MSVC BOTAN_TARGET_OS_HAS_GMTIME_S _SCL_SECURE_NO_WARNINGS DEFINES += BOTAN_BUILD_COMPILER_IS_MSVC BOTAN_TARGET_OS_HAS_GMTIME_S _SCL_SECURE_NO_WARNINGS
} else { } else {
QMAKE_CFLAGS += -fpermissive -finline-functions -Wno-long-long QMAKE_CFLAGS += -fpermissive -finline-functions -Wno-long-long

View File

@@ -70,7 +70,7 @@ void ConnectionServer::setIpcServer(IpcServerInterface *ipcServer)
int ConnectionServer::clientProxyCount() const int ConnectionServer::clientProxyCount() const
{ {
return ipcClientProxies.size(); return static_cast<int>(ipcClientProxies.size());
} }
void ConnectionServer::timerEvent(QTimerEvent *timerEvent) void ConnectionServer::timerEvent(QTimerEvent *timerEvent)

View File

@@ -58,30 +58,30 @@ Parser::Parser(Engine *engine, const char *source, unsigned size, int variant)
switch (tk.kind) { switch (tk.kind) {
case T_LEFT_PAREN: case T_LEFT_PAREN:
parenStack.push(_tokens.size()); parenStack.push(static_cast<int>(_tokens.size()));
break; break;
case T_LEFT_BRACKET: case T_LEFT_BRACKET:
bracketStack.push(_tokens.size()); bracketStack.push(static_cast<int>(_tokens.size()));
break; break;
case T_LEFT_BRACE: case T_LEFT_BRACE:
braceStack.push(_tokens.size()); braceStack.push(static_cast<int>(_tokens.size()));
break; break;
case T_RIGHT_PAREN: case T_RIGHT_PAREN:
if (! parenStack.empty()) { if (! parenStack.empty()) {
_tokens[parenStack.top()].matchingBrace = _tokens.size(); _tokens[parenStack.top()].matchingBrace = static_cast<int>(_tokens.size());
parenStack.pop(); parenStack.pop();
} }
break; break;
case T_RIGHT_BRACKET: case T_RIGHT_BRACKET:
if (! bracketStack.empty()) { if (! bracketStack.empty()) {
_tokens[bracketStack.top()].matchingBrace = _tokens.size(); _tokens[bracketStack.top()].matchingBrace = static_cast<int>(_tokens.size());
bracketStack.pop(); bracketStack.pop();
} }
break; break;
case T_RIGHT_BRACE: case T_RIGHT_BRACE:
if (! braceStack.empty()) { if (! braceStack.empty()) {
_tokens[braceStack.top()].matchingBrace = _tokens.size(); _tokens[braceStack.top()].matchingBrace = static_cast<int>(_tokens.size());
braceStack.pop(); braceStack.pop();
} }
break; break;

View File

@@ -114,7 +114,7 @@ private:
inline int consumeToken() { inline int consumeToken() {
if (_index < int(_tokens.size())) if (_index < int(_tokens.size()))
return _index++; return _index++;
return _tokens.size() - 1; return static_cast<int>(_tokens.size()) - 1;
} }
inline const Token &tokenAt(int index) const { inline const Token &tokenAt(int index) const {
if (index == 0) if (index == 0)

View File

@@ -34,7 +34,9 @@
#include <windows.h> #include <windows.h>
#define KDEXT_64BIT #define KDEXT_64BIT
#pragma warning( disable : 4838 )
#include <wdbgexts.h> #include <wdbgexts.h>
#pragma warning( default : 4838 )
#include <dbgeng.h> #include <dbgeng.h>
typedef IDebugControl3 CIDebugControl; typedef IDebugControl3 CIDebugControl;

View File

@@ -45,7 +45,7 @@ inline Botan::byte *convertByteArray(QByteArray &a)
inline QByteArray convertByteArray(const Botan::SecureVector<Botan::byte> &v) inline QByteArray convertByteArray(const Botan::SecureVector<Botan::byte> &v)
{ {
return QByteArray(reinterpret_cast<const char *>(v.begin()), v.size()); return QByteArray(reinterpret_cast<const char *>(v.begin()), static_cast<int>(v.size()));
} }
inline const char *botanKeyExchangeAlgoName(const QByteArray &rfcAlgoName) inline const char *botanKeyExchangeAlgoName(const QByteArray &rfcAlgoName)

View File

@@ -82,11 +82,11 @@ void SshAbstractCryptoFacility::recreateKeys(const SshKeyExchange &kex)
BlockCipher * const cipher BlockCipher * const cipher
= af.prototype_block_cipher(botanCryptAlgoName(rfcCryptAlgoName))->clone(); = af.prototype_block_cipher(botanCryptAlgoName(rfcCryptAlgoName))->clone();
m_cipherBlockSize = cipher->block_size(); m_cipherBlockSize = static_cast<quint32>(cipher->block_size());
const QByteArray ivData = generateHash(kex, ivChar(), m_cipherBlockSize); const QByteArray ivData = generateHash(kex, ivChar(), m_cipherBlockSize);
const InitializationVector iv(convertByteArray(ivData), m_cipherBlockSize); const InitializationVector iv(convertByteArray(ivData), m_cipherBlockSize);
const quint32 keySize = cipher->key_spec().maximum_keylength(); const quint32 keySize = static_cast<quint32>(cipher->key_spec().maximum_keylength());
const QByteArray cryptKeyData = generateHash(kex, keyChar(), keySize); const QByteArray cryptKeyData = generateHash(kex, keyChar(), keySize);
SymmetricKey cryptKey(convertByteArray(cryptKeyData), keySize); SymmetricKey cryptKey(convertByteArray(cryptKeyData), keySize);
Keyed_Filter * const cipherMode Keyed_Filter * const cipherMode
@@ -118,8 +118,9 @@ void SshAbstractCryptoFacility::convert(QByteArray &data, quint32 offset,
} }
m_pipe->process_msg(reinterpret_cast<const byte *>(data.constData()) + offset, m_pipe->process_msg(reinterpret_cast<const byte *>(data.constData()) + offset,
dataSize); dataSize);
quint32 bytesRead = m_pipe->read(reinterpret_cast<byte *>(data.data()) + offset, // Can't use Pipe::LAST_MESSAGE because of a VC bug.
dataSize, m_pipe->message_count() - 1); // Can't use Pipe::LAST_MESSAGE because of a VC bug. quint32 bytesRead = static_cast<quint32>(m_pipe->read(
reinterpret_cast<byte *>(data.data()) + offset, dataSize, m_pipe->message_count() - 1));
if (bytesRead != dataSize) { if (bytesRead != dataSize) {
throw SshClientException(SshInternalError, throw SshClientException(SshInternalError,
QLatin1String("Internal error: Botan::Pipe::read() returned unexpected value")); QLatin1String("Internal error: Botan::Pipe::read() returned unexpected value"));
@@ -261,7 +262,8 @@ bool SshEncryptionFacility::createAuthenticationKeyFromPKCS8(const QByteArray &p
<< rsaKey->get_d(); << rsaKey->get_d();
} else if (auto * const ecdsaKey = dynamic_cast<ECDSA_PrivateKey *>(m_authKey.data())) { } else if (auto * const ecdsaKey = dynamic_cast<ECDSA_PrivateKey *>(m_authKey.data())) {
const BigInt value = ecdsaKey->private_value(); const BigInt value = ecdsaKey->private_value();
m_authKeyAlgoName = SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(value.bytes()); m_authKeyAlgoName = SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(
static_cast<int>(value.bytes()));
pubKeyParams << ecdsaKey->public_point().get_affine_x() pubKeyParams << ecdsaKey->public_point().get_affine_x()
<< ecdsaKey->public_point().get_affine_y(); << ecdsaKey->public_point().get_affine_y();
allKeyParams << pubKeyParams << value; allKeyParams << pubKeyParams << value;
@@ -346,7 +348,8 @@ bool SshEncryptionFacility::createAuthenticationKeyFromOpenSSL(const QByteArray
} else { } else {
BigInt privKey; BigInt privKey;
sequence.decode_octet_string_bigint(privKey); sequence.decode_octet_string_bigint(privKey);
m_authKeyAlgoName = SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(privKey.bytes()); m_authKeyAlgoName = SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(
static_cast<int>(privKey.bytes()));
const EC_Group group(SshCapabilities::oid(m_authKeyAlgoName)); const EC_Group group(SshCapabilities::oid(m_authKeyAlgoName));
auto * const key = new ECDSA_PrivateKey(m_rng, group, privKey); auto * const key = new ECDSA_PrivateKey(m_rng, group, privKey);
m_authKey.reset(key); m_authKey.reset(key);

View File

@@ -115,7 +115,7 @@ void SshKeyGenerator::generatePkcs8KeyString(const KeyPtr &key, bool privateKey,
keyData = &m_publicKey; keyData = &m_publicKey;
} }
pipe.end_msg(); pipe.end_msg();
keyData->resize(pipe.remaining(pipe.message_count() - 1)); keyData->resize(static_cast<int>(pipe.remaining(pipe.message_count()) - 1));
pipe.read(convertByteArray(*keyData), keyData->size(), pipe.read(convertByteArray(*keyData), keyData->size(),
pipe.message_count() - 1); pipe.message_count() - 1);
} }
@@ -147,7 +147,8 @@ void SshKeyGenerator::generateOpenSslPublicKeyString(const KeyPtr &key)
case Ecdsa: { case Ecdsa: {
const auto ecdsaKey = key.dynamicCast<ECDSA_PrivateKey>(); const auto ecdsaKey = key.dynamicCast<ECDSA_PrivateKey>();
q = convertByteArray(EC2OSP(ecdsaKey->public_point(), PointGFp::UNCOMPRESSED)); q = convertByteArray(EC2OSP(ecdsaKey->public_point(), PointGFp::UNCOMPRESSED));
keyId = SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(ecdsaKey->private_value().bytes()); keyId = SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(
static_cast<int>(ecdsaKey->private_value().bytes()));
break; break;
} }
} }

View File

@@ -96,7 +96,7 @@ QByteArray AbstractSshPacket::encodeMpInt(const Botan::BigInt &number)
if (number.is_zero()) if (number.is_zero())
return QByteArray(4, 0); return QByteArray(4, 0);
int stringLength = number.bytes(); int stringLength = static_cast<int>(number.bytes());
const bool positiveAndMsbSet = number.sign() == Botan::BigInt::Positive const bool positiveAndMsbSet = number.sign() == Botan::BigInt::Positive
&& (number.byte_at(stringLength - 1) & 0x80); && (number.byte_at(stringLength - 1) & 0x80);
if (positiveAndMsbSet) if (positiveAndMsbSet)

View File

@@ -296,7 +296,7 @@ void blockingContainerMapReduce(QFutureInterface<ReduceResult> &futureInterface,
std::forward<InitFunction>(init), std::forward<MapFunction>(map), std::forward<InitFunction>(init), std::forward<MapFunction>(map),
std::forward<ReduceFunction>(reduce), std::forward<ReduceFunction>(reduce),
std::forward<CleanUpFunction>(cleanup), std::forward<CleanUpFunction>(cleanup),
option, container.size()); option, static_cast<int>(container.size()));
} }
template <typename Container, typename InitFunction, typename MapFunction, typename ReduceResult, template <typename Container, typename InitFunction, typename MapFunction, typename ReduceResult,

View File

@@ -28,6 +28,7 @@
#include "fileutils.h" #include "fileutils.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# include <windows.h> # include <windows.h>
# include <io.h>
#else #else
# include <unistd.h> # include <unistd.h>
# include <sys/stat.h> # include <sys/stat.h>
@@ -97,7 +98,7 @@ bool SaveFile::commit()
return false; return false;
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
FlushFileBuffers(reinterpret_cast<HANDLE>(handle())); FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(handle())));
#elif _POSIX_SYNCHRONIZED_IO > 0 #elif _POSIX_SYNCHRONIZED_IO > 0
fdatasync(handle()); fdatasync(handle());
#else #else

View File

@@ -203,7 +203,7 @@ int alignedSize(int size) { return (size + 3) & ~3; }
static int qStringSize(const std::string &ba) static int qStringSize(const std::string &ba)
{ {
int l = 4 + ba.length(); int l = 4 + static_cast<int>(ba.length());
return alignedSize(l); return alignedSize(l);
} }
@@ -252,7 +252,7 @@ public:
void operator=(const std::string &ba) void operator=(const std::string &ba)
{ {
d->length = ba.length(); d->length = static_cast<int>(ba.length());
memcpy(d->utf8, ba.data(), ba.length()); memcpy(d->utf8, ba.data(), ba.length());
} }
@@ -581,7 +581,7 @@ public:
int objectPosition; int objectPosition;
std::vector<uint32_t> offsets; std::vector<uint32_t> offsets;
Entry *entryAt(int i) const { Entry *entryAt(size_t i) const {
return reinterpret_cast<Entry *>(parser->data + objectPosition + offsets[i]); return reinterpret_cast<Entry *>(parser->data + objectPosition + offsets[i]);
} }
}; };
@@ -2505,7 +2505,8 @@ JsonObject::iterator JsonObject::insert(const std::string &key, const JsonValue
Internal::Entry *e = o->entryAt(pos); Internal::Entry *e = o->entryAt(pos);
e->value.type = val.t; e->value.type = val.t;
e->value.intValue = isIntValue; e->value.intValue = isIntValue;
e->value.value = Internal::Value::valueToStore(val, (char *)e - (char *)o + valueOffset); e->value.value = Internal::Value::valueToStore(val, static_cast<uint32_t>((char *)e - (char *)o)
+ valueOffset);
Internal::copyString((char *)(e + 1), key); Internal::copyString((char *)(e + 1), key);
if (valueSize) if (valueSize)
Internal::Value::copyData(val, (char *)e + valueOffset, isIntValue); Internal::Value::copyData(val, (char *)e + valueOffset, isIntValue);
@@ -3475,7 +3476,7 @@ std::string JsonDocument::toJson(JsonFormat format) const
*/ */
JsonDocument JsonDocument::fromJson(const std::string &json, JsonParseError *error) JsonDocument JsonDocument::fromJson(const std::string &json, JsonParseError *error)
{ {
Internal::Parser parser(json.data(), json.length()); Internal::Parser parser(json.data(), static_cast<int>(json.length()));
return parser.parse(error); return parser.parse(error);
} }
@@ -4008,7 +4009,7 @@ JsonDocument Parser::parse(JsonParseError *error)
std::cerr << ">>>>> parser begin"; std::cerr << ">>>>> parser begin";
#endif #endif
// allocate some space // allocate some space
dataLength = std::max(end - json, std::ptrdiff_t(256)); dataLength = static_cast<int>(std::max(end - json, std::ptrdiff_t(256)));
data = (char *)malloc(dataLength); data = (char *)malloc(dataLength);
// fill in Header data // fill in Header data
@@ -4054,7 +4055,7 @@ error:
std::cerr << ">>>>> parser error"; std::cerr << ">>>>> parser error";
#endif #endif
if (error) { if (error) {
error->offset = json - head; error->offset = static_cast<int>(json - head);
error->error = lastError; error->error = lastError;
} }
free(data); free(data);
@@ -4068,8 +4069,8 @@ void Parser::ParsedObject::insert(uint32_t offset)
size_t min = 0; size_t min = 0;
size_t n = offsets.size(); size_t n = offsets.size();
while (n > 0) { while (n > 0) {
int half = n >> 1; size_t half = n >> 1;
int middle = min + half; size_t middle = min + half;
if (*entryAt(middle) >= *newEntry) { if (*entryAt(middle) >= *newEntry) {
n = half; n = half;
} else { } else {
@@ -4127,7 +4128,7 @@ bool Parser::parseObject()
int table = objectOffset; int table = objectOffset;
// finalize the object // finalize the object
if (parsedObject.offsets.size()) { if (parsedObject.offsets.size()) {
int tableSize = parsedObject.offsets.size()*sizeof(uint32_t); int tableSize = static_cast<int>(parsedObject.offsets.size()) * sizeof(uint32_t);
table = reserveSpace(tableSize); table = reserveSpace(tableSize);
memcpy(data + table, &*parsedObject.offsets.begin(), tableSize); memcpy(data + table, &*parsedObject.offsets.begin(), tableSize);
} }
@@ -4136,7 +4137,7 @@ bool Parser::parseObject()
o->tableOffset = table - objectOffset; o->tableOffset = table - objectOffset;
o->size = current - objectOffset; o->size = current - objectOffset;
o->is_object = true; o->is_object = true;
o->length = parsedObject.offsets.size(); o->length = static_cast<int>(parsedObject.offsets.size());
DEBUG << "current=" << current; DEBUG << "current=" << current;
END; END;
@@ -4218,7 +4219,7 @@ bool Parser::parseArray()
int table = arrayOffset; int table = arrayOffset;
// finalize the object // finalize the object
if (values.size()) { if (values.size()) {
int tableSize = values.size()*sizeof(Value); int tableSize = static_cast<int>(values.size() * sizeof(Value));
table = reserveSpace(tableSize); table = reserveSpace(tableSize);
memcpy(data + table, values.data(), tableSize); memcpy(data + table, values.data(), tableSize);
} }
@@ -4227,7 +4228,7 @@ bool Parser::parseArray()
a->tableOffset = table - arrayOffset; a->tableOffset = table - arrayOffset;
a->size = current - arrayOffset; a->size = current - arrayOffset;
a->is_object = false; a->is_object = false;
a->length = values.size(); a->length = static_cast<int>(values.size());
DEBUG << "current=" << current; DEBUG << "current=" << current;
END; END;
@@ -4558,7 +4559,7 @@ bool Parser::parseString()
const char c = *json; const char c = *json;
if (c == '"') { if (c == '"') {
// write string length and padding. // write string length and padding.
const int len = json - inStart; const int len = static_cast<int>(json - inStart);
const int pos = reserveSpace(4 + alignedSize(len)); const int pos = reserveSpace(4 + alignedSize(len));
toInternal(data + pos, inStart, len); toInternal(data + pos, inStart, len);
END; END;

View File

@@ -236,6 +236,7 @@ void dummyStatement(...) {}
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <windows.h> #include <windows.h>
#include <basetsd.h>
#undef min #undef min
#undef max #undef max
#endif #endif
@@ -276,7 +277,11 @@ void dummyStatement(...) {}
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
uint qHash(const QMap<int, int> &) { return 0; } uint qHash(const QMap<int, int> &) { return 0; }
uint qHash(const double & f) { return int(f); } uint qHash(const double & f) { return int(f); }
uint qHash(const QPointer<QObject> &p) { return (ulong)p.data(); } #ifdef Q_OS_WIN
uint qHash(const QPointer<QObject> &p) { return PtrToUint(p.data()); }
#else
uint qHash(const QPointer<QObject> &p) { (ulong)p.data(); }
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
@@ -3336,7 +3341,7 @@ namespace lambda {
{ {
std::string x; std::string x;
auto f = [&] () -> const std::string & { auto f = [&] () -> const std::string & {
int z = x.size(); size_t z = x.size();
Q_UNUSED(z); Q_UNUSED(z);
return x; return x;
}; };