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

Review toupper/tolower uses [Qt]

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • 5.15.13, 6.2.8, 6.4.3, 6.5.0, 6.6.0
    • 5.15.11, 6.2.6, 6.4.1, 6.5.0 FF
    • Core: Other
    • None
    • 5
    • f11a9b203 (6.4), 536e17372 (dev), a50b7f500 (tqtc/lts-5.15), 4e647ab8a (tqtc/lts-6.2), b8c2a0c18 (dev), 81be57a99 (6.4), 9c63b9fda (6.5), 78db5cb64 (dev), 2a865831a (tqtc/lts-6.2), 9daf3961c (tqtc/lts-5.15), 43f6e10a7 (6.5), 115b1eab8 (dev)
    • Foundation Sprint 72

    Description

      The C toupper/tolower functions are locale-dependent. Given the right locale (Türkiye, e.g.):

      • tolower(I) is either
        • ı (LATIN SMALL LETTER DOTLESS I; if representable in current charset) or
        • I (unchanged; if it isn't)
      • toupper(i) is either
        • İ (LATIN CAPITAL LETTER I WITH DOT ABOVE; if representable) or
        • i (unchanged; if it isn't)

      Both results are wrong.

      Also, since toupper/tolower are UB unless the argument is 0..255 or EOF, it's UB to even feed a char! You need to cast to uchar first! So, basically all our uses of toupper/tolower are UB!

      Please check your respective code bases, book patches, if any, onto this ticket, and, once merged, remove your component from the Jira field.

      We have QtMiscUtils::asciiToLower() in QtCore/private/qtools_p.h. It's been backported to 5.15 We don't have asciiToUpper(). You can either port to asciiToLower() or use caseCompareAscii() (which may not be available in Qt 6.2 and 5.15), or wait for asciiToUpper() (from https://codereview.qt-project.org/c/qt/qtbase/+/449457) to make its way through the branches.

      It doesn't look like we have uses in public header files. If you find one, then you need to pull the code out-of-line.

      Attachments

        Issue Links

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

          Activity

            People

              mmutz Marc Mutz
              mmutz Marc Mutz
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes