path: root/src/corelib/itemmodels
diff options
authorMarc Mutz <>2016-04-01 23:19:26 +0200
committerMarc Mutz <>2016-04-05 06:52:28 +0000
commitb5eb553bf3bd6b9aad79241a65b9bebb40a848fd (patch)
tree93041fa5aa23903aa3471f411554f6ed70378f5e /src/corelib/itemmodels
parent8ce657d0279566ef327af1b88339534041ddc012 (diff)
Fix UB (shift of negative number) in qHash(QModelIndex)
Found by UBSan: itemmodels/qabstractitemmodel.h:426:28: runtime error: left shift of negative value -1 Fix by casting the lhs of the left-shift operator to uint before shifting. Since Qt assumes two's complement repre- sentation of signed integers, this should yield the same result as the old code, but without UBs. It is critically important that the result is identical to the old code (modulo the compiler exploiting the UB, which this patch aims to prevent even in future compilers), because the function is inline, and changing the hash value would mean changing the layout of a QHash<QModelIndex,.> between users compiled against the old and new libraries. Change-Id: I7b826a34fb78b02021e40c3f85fd11af398dbec4 Reviewed-by: Olivier Goffart (Woboq GmbH) <>
Diffstat (limited to 'src/corelib/itemmodels')
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h
index 096e67c513..454134720d 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.h
+++ b/src/corelib/itemmodels/qabstractitemmodel.h
@@ -423,7 +423,7 @@ inline Qt::ItemFlags QModelIndex::flags() const
{ return m ? m->flags(*this) : Qt::ItemFlags(); }
inline uint qHash(const QModelIndex &index) Q_DECL_NOTHROW
-{ return uint((index.row() << 4) + index.column() + index.internalId()); }
+{ return uint((uint(index.row()) << 4) + index.column() + index.internalId()); }