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) <ogoffart@woboq.com>bb10
parent
8ce657d027
commit
b5eb553bf3
|
|
@ -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()); }
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue