diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-01-02 15:16:34 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-01-03 15:15:16 +0100 |
commit | 65b8514cb5eae5a7055f55fd375da7b2eea487d6 (patch) | |
tree | a1860cda3959538dd066d658b233f920054548b2 | |
parent | 4d8ee1b3493b79a6f1cd5200e6102711c0102c9e (diff) |
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>
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 2 | ||||
-rw-r--r-- | src/corelib/text/qbytearray.h | 2 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qarraydata.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 4 |
6 files changed, 9 insertions, 9 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 23296896b2..3fa1868437 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -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()); diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 863898f7e2..e3fec1e62c 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -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) { diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index a611410fac..0350dabfc9 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -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) diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 00f6dfe6ef..497eae1f7f 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -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); diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 6b110c5143..0d2be5d51c 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -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 diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index 7bba7241e9..a17cf4a101 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -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); } |