Fix MSVC conversion warnings in new bytearray code.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Tue, 17 Apr 2012 15:26:29 +0000 (17:26 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 20 Apr 2012 10:46:47 +0000 (12:46 +0200)
Change-Id: Ifc81564daf3fef0d7f08ae8d250ba41d3b1d5b0f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
src/corelib/tools/qarraydata.cpp
src/corelib/tools/qarraydata.h
src/corelib/tools/qbytearray.cpp

index f1b88d5..328d39c 100644 (file)
@@ -82,7 +82,7 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
 
     // Allocate additional space if array is growing
     if (options & Grow)
-        capacity = qAllocMore(objectSize * capacity, headerSize) / objectSize;
+        capacity = qAllocMore(objectSize * capacity, headerSize) / int(objectSize);
 
     size_t allocSize = headerSize + objectSize * capacity;
 
index 78fbc9c..4d79c92 100644 (file)
@@ -169,7 +169,7 @@ struct QTypedArrayData
 
             result->offset = reinterpret_cast<const char *>(data)
                 - reinterpret_cast<const char *>(result);
-            result->size = n;
+            result->size = int(n);
         }
         return result;
     }
index 42150ef..b5e7f28 100644 (file)
@@ -131,7 +131,7 @@ char *qstrcpy(char *dst, const char *src)
     if (!src)
         return 0;
 #if defined(_MSC_VER) && _MSC_VER >= 1400
-    int len = strlen(src);
+    const int len = int(strlen(src));
        // This is actually not secure!!! It will be fixed
        // properly in a later release!
     if (len >= 0 && strcpy_s(dst, len+1, src) == 0)
@@ -914,12 +914,13 @@ QByteArray &QByteArray::operator=(const char *str)
     } else if (!*str) {
         x = Data::allocate(0);
     } else {
-        int len = strlen(str);
-        if (d->ref.isShared() || uint(len) + 1u > d->alloc
-                || (len < d->size && uint(len) + 1u < uint(d->alloc >> 1)))
-            reallocData(uint(len) + 1u, d->detachFlags());
+        const int len = int(strlen(str));
+        const uint fullLen = len + 1;
+        if (d->ref.isShared() || fullLen > d->alloc
+                || (len < d->size && fullLen < uint(d->alloc >> 1)))
+            reallocData(fullLen, d->detachFlags());
         x = d;
-        memcpy(x->data(), str, uint(len) + 1u); // include null terminator
+        memcpy(x->data(), str, fullLen); // include null terminator
         x->size = len;
     }
     x->ref.ref();
@@ -1322,7 +1323,7 @@ QByteArray::QByteArray(const char *data, int size)
         d = Data::sharedNull();
     } else {
         if (size < 0)
-            size = strlen(data);
+            size = int(strlen(data));
         if (!size) {
             d = Data::allocate(0);
         } else {
@@ -1631,7 +1632,7 @@ QByteArray &QByteArray::append(const QByteArray &ba)
 QByteArray& QByteArray::append(const char *str)
 {
     if (str) {
-        int len = strlen(str);
+        const int len = int(strlen(str));
         if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
             reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow);
         memcpy(d->data() + d->size, str, len + 1); // include null terminator
@@ -2515,7 +2516,7 @@ bool QByteArray::startsWith(const char *str) const
 {
     if (!str || !*str)
         return true;
-    int len = strlen(str);
+    const int len = int(strlen(str));
     if (d->size < len)
         return false;
     return qstrncmp(d->data(), str, len) == 0;
@@ -2560,7 +2561,7 @@ bool QByteArray::endsWith(const char *str) const
 {
     if (!str || !*str)
         return true;
-    int len = strlen(str);
+    const int len = int(strlen(str));
     if (d->size < len)
         return false;
     return qstrncmp(d->data() + d->size - len, str, len) == 0;