MSVC: Fix integer conversion warnings in containers

Add some casts, fixing warnings like:
src/corelib/text/qbytearray.h(490): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
src/corelib/text/qstring.h(1045): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
src/corelib/tools/qarraydatapointer.h(80): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
src/corelib/tools/qarraydatapointer.h(75): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
src/corelib/text/qbytearray.h(490): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data

Change-Id: I221db4d5b660224f0fc1869248802c496db1b91c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Friedemann Kleint 2020-01-02 15:16:34 +01:00
parent 4d8ee1b349
commit 65b8514cb5
6 changed files with 9 additions and 9 deletions

View File

@ -1218,7 +1218,7 @@ QByteArray &QByteArray::operator=(const char *str)
d = QByteArrayData(pair.first, pair.second, 0);
} else {
const int len = int(strlen(str));
const size_t fullLen = len + 1;
const uint fullLen = uint(len) + 1;
if (d->needsDetach() || fullLen > d->allocatedCapacity()
|| (len < size() && fullLen < (d->allocatedCapacity() >> 1)))
reallocData(fullLen, d->detachFlags());

View File

@ -487,7 +487,7 @@ inline QByteArray::QByteArray(const QByteArray &a) noexcept : d(a.d)
{}
inline int QByteArray::capacity() const
{ int realCapacity = d->constAllocatedCapacity(); return realCapacity ? realCapacity - 1 : 0; }
{ const auto realCapacity = d->constAllocatedCapacity(); return realCapacity ? int(realCapacity) - 1 : 0; }
inline void QByteArray::reserve(int asize)
{

View File

@ -1042,7 +1042,7 @@ inline void QString::clear()
inline QString::QString(const QString &other) noexcept : d(other.d)
{ }
inline int QString::capacity() const
{ int realCapacity = d->constAllocatedCapacity(); return realCapacity ? realCapacity - 1 : 0; }
{ const auto realCapacity = d->constAllocatedCapacity(); return realCapacity ? int(realCapacity) - 1 : 0; }
inline QString &QString::setNum(short n, int base)
{ return setNum(qlonglong(n), base); }
inline QString &QString::setNum(ushort n, int base)

View File

@ -233,7 +233,7 @@ void *QArrayData::allocate(QArrayData **dptr, size_t objectSize, size_t alignmen
// find where offset should point to so that data() is aligned to alignment bytes
data = (quintptr(header) + sizeof(QArrayData) + alignment - 1)
& ~(alignment - 1);
header->alloc = capacity;
header->alloc = uint(capacity);
}
*dptr = header;
@ -262,7 +262,7 @@ QArrayData::reallocateUnaligned(QArrayData *data, void *dataPointer,
options |= AllocatedDataType | MutableData;
QArrayData *header = reallocateData(data, allocSize, options);
if (header) {
header->alloc = capacity;
header->alloc = uint(capacity);
dataPointer = reinterpret_cast<char *>(header) + offset;
}
return qMakePair(static_cast<QArrayData *>(header), dataPointer);

View File

@ -158,7 +158,7 @@ struct QPodArrayOps
::memmove(static_cast<void *>(where + n), static_cast<void *>(where),
(static_cast<const T*>(this->end()) - where) * sizeof(T));
this->size += n; // PODs can't throw on copy
this->size += int(n); // PODs can't throw on copy
while (n--)
*where++ = t;
}
@ -655,7 +655,7 @@ struct QMovableArrayOps
copier.copy(n, t);
displace.commit();
this->size += n;
this->size += int(n);
}
// use moving insert

View File

@ -71,12 +71,12 @@ public:
}
QArrayDataPointer(Data *header, T *adata, size_t n = 0) noexcept
: d(header), ptr(adata), size(n)
: d(header), ptr(adata), size(int(n))
{
}
explicit QArrayDataPointer(QPair<QTypedArrayData<T> *, T *> adata, size_t n = 0)
: d(adata.first), ptr(adata.second), size(n)
: d(adata.first), ptr(adata.second), size(int(n))
{
Q_CHECK_PTR(d);
}