Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-18249

QString::toShort(.) erroneously accepts and truncates values

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.0.0
    • 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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Eddy Edward Welbourne
            ladifrk1 Tobias Bergemann
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes