Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.6.3
-
None
-
Microsoft® Windows Vista Business Version 6.0.6002 Service Pack 2 Build 6002
Description
QString::toShort(.) accepts values it should not accept and can give wrong results.
Example:
QString str("100007FFF"); bool ok; short hex = str.toShort(&ok, 16);
After the call to QString::toShort(.), ok is true, and hex is 0x7FFF (i.e., 0x100007FFF apparently was truncated to 0x7FFF). The conversion using QString::toShort(.) should have failed instead of returning a wrong value.
What happens is that QString::toShort(.) uses QString::toLongLong(.), but stores the result of the call to QString::toLongLong(.) in a long, thereby truncating it. Furthermore, QString::toShort(.) does not check whether the call to QString::toLongLong(.) actually succeeded.