The function was crashing when an unsupported type id was given
as an input argument.
Change-Id: I2b0e3e6d43f6f248dc71532f8e6485efe68e8120
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
if (currentType == uint(targetTypeId))
return true;
+ if (targetTypeId < 0 || targetTypeId >= QMetaType::User)
+ return false;
// FIXME It should be LastCoreType intead of Uuid
if (currentType > int(QMetaType::QUuid) || targetTypeId > int(QMetaType::QUuid)) {
QCOMPARE(val.canConvert(QVariant::Time), TimeCast);
QCOMPARE(val.canConvert(QVariant::UInt), UIntCast);
QCOMPARE(val.canConvert(QVariant::ULongLong), ULongLongCast);
+
+ // Invalid type ids
+ QCOMPARE(val.canConvert(-1), false);
+ QCOMPARE(val.canConvert(-23), false);
+ QCOMPARE(val.canConvert(-23876), false);
+ QCOMPARE(val.canConvert(23876), false);
}
void tst_QVariant::toInt_data()