QByteArrayMatcher: fix undefined shift

The REHASH macro is used in qFindByteArray() with a char argument.
Applying the shift operator promotes (a) to int. The check in
REHASH, however, checks for the shift being permissible for
_unsigned_ ints.

Since hashHaystack is a uint, too, rectify by casting (a) to
uint prior to shifting.

Found by UBSan:

  src/corelib/tools/qbytearraymatcher.cpp:314:72: runtime error: left shift of 34 by 30 places cannot be represented in type 'int'

Change-Id: Id09c037d570ca70b49f87ad22bed31bbb7dcc7fb
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-01-18 13:43:37 +01:00
parent b18e6396bd
commit 390ea21873

View File

@ -256,7 +256,7 @@ static int qFindByteArrayBoyerMoore(
#define REHASH(a) \
if (sl_minus_1 < sizeof(uint) * CHAR_BIT) \
hashHaystack -= (a) << sl_minus_1; \
hashHaystack -= uint(a) << sl_minus_1; \
hashHaystack <<= 1
/*!