summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-05-05 13:54:06 -0700
committerThiago Macieira <thiago.macieira@intel.com>2017-05-06 02:57:41 +0000
commit02700cf6c23f1095a9187230220dd9b97082d61a (patch)
tree50b3b8fb6061152d78607ded24aff0e36a821aff /src/corelib
parent9e1f60053a7169cc9098cc8823e1daae6d58331c (diff)
Add an extra check for qssize_t's size and type
The definitions of size_t and ptrdiff_t ([support.types.layout] p2 and p3 respectively) do not specify that they need to be as big as a pointer. They just need to be big enough to hold the size of the largest object and the biggest array subscript, respectively, the platform supports (e.g., 16-bit DOS would have them as 16-bit in all memory models, except huge). But we depend on them actually being the size of a pointer in many places, such as in QArrayData::offset, that stores the linear distance from the end of the structure to the beginning of the data, wherever it is in memory. It's also a good idea to verify that qptrdiff and qssize_t are the same type. Change-Id: I9ad33fff8b634979bdbafffd14bbd1223afc58e8 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qglobal.cpp5
-rw-r--r--src/corelib/global/qglobal.h3
2 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 150ae7cf49..bb944c4d8e 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -140,6 +140,11 @@ Q_STATIC_ASSERT_X(std::numeric_limits<float>::has_infinity &&
Q_STATIC_ASSERT_X(std::numeric_limits<float>::radix == 2,
"Qt assumes binary IEEE 754 floating point");
+// not required by the definition of size_t, but we depend on this
+Q_STATIC_ASSERT_X(sizeof(size_t) == sizeof(void *), "size_t and a pointer don't have the same size");
+Q_STATIC_ASSERT(sizeof(size_t) == sizeof(qssize_t)); // implied by the definition
+Q_STATIC_ASSERT((std::is_same<qssize_t, qptrdiff>::value));
+
/*!
\class QFlag
\inmodule QtCore
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 14c17d1ce3..51dad31bba 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -436,6 +436,9 @@ namespace QtPrivate {
sizeof(void *) == sizeof(quintptr)
&& sizeof(void *) == sizeof(qptrdiff)
+
+ size_t and qssize_t are not guaranteed to be the same size as a pointer, but
+ they usually are.
*/
template <int> struct QIntegerForSize;
template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qint8 Signed; };