Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.15.2
-
None
-
MSVC2019
Description
While using QString::toShort to convert a 4-digit string in base 16, it always returns 0 if the string is greater than "7FFF".
For example: QString("FF73").toShort(nullptr, 16) will return 0.
The qt source code is as follows:
short QString::toShort(bool *ok, int base) const
{
long v = toLongLong(ok, base);
if (v < SHRT_MIN || v > SHRT_MAX)Unknown macro: { if (ok) *ok = false; v = 0; }return (short)v;
}
where SHRT_MIN is -32768 and SHRT_MAX is 32767.
Take "FF73" as example, converting "FF73" to a longlong will be 65395. Then this function will consider it out of range and return 0. However, shouldn't this function be able to convert string "0000" to "FFFF" to signed short -32768 to 32767? Now it can only convert string "0000" to "7FFF", and "8000" to "FFFF" will be considered as out of range and always return 0.