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

QObject::tr() will assert in debug if the final character is '%'

    XMLWordPrintable

Details

    • c365fa49d85810c6ad09bb5f43b5081cd7543bf1 (qt/qtbase/5.12)

    Description

      When attempting to format a string which happens to end in a percentage and contain a plural form I ended up writing a tr() line a bit like this:

          auto str1 = QObject::tr("%n point(s) - %1%", "", 2).arg(QString::number(37.5f));
      

      This worked fine in release, however in debug it asserts in QCoreApplication::replacePercentN() which calls at() beyond the final %. There's nothing about this string which makes that final % ambiguous, and that seems like a trivial indexing error. However if for some reason that input string shouldn't be allowed then the documentation should probably note it.

      When the attached program is run we see:

      ASSERT: "uint(i) < uint(size())" in file c:\qt\msvc2013\x86_64\5.5.1\qtbase\include\qtcore\../../src/corelib/tools/qstring.h, line 851
      Debug Error!
      
      Program: C:\Qt\msvc2013\x86_64\5.5.1\qtbase\lib\Qt5Cored.dll
      Module: 5.5.1
      File: global\qglobal.cpp
      Line: 2966
      
      ASSERT: "uint(i) < uint(size())" in file c:\qt\msvc2013\x86_64\5.5.1\qtbase\include\qtcore\../../src/corelib/tools/qstring.h, line 851
      
      (Press Retry to debug the application)
      

      Attachments

        1. main.cpp
          0.5 kB
        2. TrBacktrace.txt
          3 kB
        For Gerrit Dashboard: QTBUG-57171
        # Subject Branch Project Status CR V

        Activity

          People

            buddenha Oswald Buddenhagen
            alexelliott Alex Elliott
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes