Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Assert : "uint(i) < uint(size())" in file ..\..\include/QtCore ../src/corelib/tools/qstring.h line 879

Assert : "uint(i) < uint(size())" in file ..\..\include/QtCore ../src/corelib/tools/qstring.h line 879

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samzhcs1
    wrote on last edited by
    #1

    Hi, Please help me analyze what is the reason for this Assert warning.
    the code is :
    void LoadTxtFile(QTextStream &tsFileIn)
    {
    QLoggingCategory maxCol("MaxColumn : ");
    QString txtLine;
    QStringList celList;

    int row = 0;
    int col = 0;
    int celListLen = 0;
    while (!tsFileIn.atEnd()) {
    
        txtLine = tsFileIn.readLine();
        tstdOut << txtLine << endl;
        row += 1;
    
        celList = txtLine.split(QChar('\t'));
        if (!celList.isEmpty())
            celListLen = celList.count();
    
        if ( col < celListLen ) {
            col = celListLen;    //max column number of the text file.
            if ( col > 26 ) {
                qCWarning(maxCol) << "Column Number Limit is 26!";
                return;
            }
        }
    

    }

    I tried to comment some codes, and find, the warning is from the following block.
    if ( col < celListLen ) {
    col = celListLen; //max column number of the text file.
    if ( col > 26 ) {
    qCWarning(maxCol) << "Column Number Limit is 26!";
    return;
    }
    }
    But I don't understand why it produces the warning.

    jsulmJ Paul ColbyP 2 Replies Last reply
    0
    • S samzhcs1

      Hi, Please help me analyze what is the reason for this Assert warning.
      the code is :
      void LoadTxtFile(QTextStream &tsFileIn)
      {
      QLoggingCategory maxCol("MaxColumn : ");
      QString txtLine;
      QStringList celList;

      int row = 0;
      int col = 0;
      int celListLen = 0;
      while (!tsFileIn.atEnd()) {
      
          txtLine = tsFileIn.readLine();
          tstdOut << txtLine << endl;
          row += 1;
      
          celList = txtLine.split(QChar('\t'));
          if (!celList.isEmpty())
              celListLen = celList.count();
      
          if ( col < celListLen ) {
              col = celListLen;    //max column number of the text file.
              if ( col > 26 ) {
                  qCWarning(maxCol) << "Column Number Limit is 26!";
                  return;
              }
          }
      

      }

      I tried to comment some codes, and find, the warning is from the following block.
      if ( col < celListLen ) {
      col = celListLen; //max column number of the text file.
      if ( col > 26 ) {
      qCWarning(maxCol) << "Column Number Limit is 26!";
      return;
      }
      }
      But I don't understand why it produces the warning.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @samzhcs1 Is ut this line:

      qCWarning(maxCol) << "Column Number Limit is 26!";
      

      ?
      Is maxCol a number or a category?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • S samzhcs1

        Hi, Please help me analyze what is the reason for this Assert warning.
        the code is :
        void LoadTxtFile(QTextStream &tsFileIn)
        {
        QLoggingCategory maxCol("MaxColumn : ");
        QString txtLine;
        QStringList celList;

        int row = 0;
        int col = 0;
        int celListLen = 0;
        while (!tsFileIn.atEnd()) {
        
            txtLine = tsFileIn.readLine();
            tstdOut << txtLine << endl;
            row += 1;
        
            celList = txtLine.split(QChar('\t'));
            if (!celList.isEmpty())
                celListLen = celList.count();
        
            if ( col < celListLen ) {
                col = celListLen;    //max column number of the text file.
                if ( col > 26 ) {
                    qCWarning(maxCol) << "Column Number Limit is 26!";
                    return;
                }
            }
        

        }

        I tried to comment some codes, and find, the warning is from the following block.
        if ( col < celListLen ) {
        col = celListLen; //max column number of the text file.
        if ( col > 26 ) {
        qCWarning(maxCol) << "Column Number Limit is 26!";
        return;
        }
        }
        But I don't understand why it produces the warning.

        Paul ColbyP Offline
        Paul ColbyP Offline
        Paul Colby
        wrote on last edited by
        #3

        Hi @samzhcs1,

        It would help to know which line of your code cause the assertion... can you run it in a debugger?

        The only thing that stands out to me is this bit:

        if (!celList.isEmpty())
            celListLen = celList.count();
        

        Here, you really should have an else celListLen = 0; (or something equivalent). You might be assuming that celListLen is already initialised to 0, but that only happens before your while loop, so within any iteration (but the first) of the while loop, you could be using a stale celListLen value.

        Just to show that more clearly, here's a cut-down version of your loop:

        int celListLen = 0;
        while (!tsFileIn.atEnd()) {
            ...
            if (!celList.isEmpty())
                celListLen = celList.count();
            // else, what is celListLen now?
            ...
        }
        

        I hope that helps.

        Cheers.

        S 1 Reply Last reply
        0
        • jsulmJ jsulm

          @samzhcs1 Is ut this line:

          qCWarning(maxCol) << "Column Number Limit is 26!";
          

          ?
          Is maxCol a number or a category?

          S Offline
          S Offline
          samzhcs1
          wrote on last edited by samzhcs1
          #4

          @jsulm A category

          jsulmJ 1 Reply Last reply
          0
          • S samzhcs1

            @jsulm A category

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @samzhcs1 Which line exactly causes the warning?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • Paul ColbyP Paul Colby

              Hi @samzhcs1,

              It would help to know which line of your code cause the assertion... can you run it in a debugger?

              The only thing that stands out to me is this bit:

              if (!celList.isEmpty())
                  celListLen = celList.count();
              

              Here, you really should have an else celListLen = 0; (or something equivalent). You might be assuming that celListLen is already initialised to 0, but that only happens before your while loop, so within any iteration (but the first) of the while loop, you could be using a stale celListLen value.

              Just to show that more clearly, here's a cut-down version of your loop:

              int celListLen = 0;
              while (!tsFileIn.atEnd()) {
                  ...
                  if (!celList.isEmpty())
                      celListLen = celList.count();
                  // else, what is celListLen now?
                  ...
              }
              

              I hope that helps.

              Cheers.

              S Offline
              S Offline
              samzhcs1
              wrote on last edited by
              #6

              @Paul-Colby Thanks. it's weird. when I run the program in debug mode, QT creator, sometimes, it shows the assert warning. but if I run the program not in debug mode, it works well.

              And every time I start the program in debug mode, before stopping at first break point, QT Creator must shows a disassembler view.
              0x7764000c cc int3
              0x7764000d <+0x0001> c3 ret
              0x7764000e <+0x0002> 90 nop
              0x7764000f <+0x0003> 90 nop
              0x77640010 <+0x0004> 90 nop
              0x77640011 <+0x0005> 90 nop
              0x77640012 <+0x0006> 90 nop
              0x77640013 <+0x0007> 90 nop
              0x77640014 <+0x0008> 90 nop
              0x77640015 <+0x0009> 90 nop
              0x77640016 <+0x000a> 90 nop
              0x77640017 <+0x000b> 90 nop
              0x77640018 <+0x000c> 90 nop
              0x77640019 <+0x000d> 90 nop
              0x7764001a <+0x000e> 90 nop
              0x7764001b <+0x000f> 90 nop
              0x7764001c <+0x0010> 90 nop
              0x7764001d <+0x0011> 90 nop
              0x7764001e <+0x0012> 90 nop
              0x7764001f <+0x0013> 90 nop
              0x77640020 <+0x0014> 8b 4c 24 04 mov 0x4(%esp),%ecx
              0x77640024 <+0x0018> f6 41 04 06 testb $0x6,0x4(%ecx)
              0x77640028 <+0x001c> 74 05 je 0x7764002f <ntdll!DbgBreakPoint+35>
              0x7764002a <+0x001e> e8 a1 1d 01 00 call 0x77651dd0 <ntdll!ZwTestAlert>
              0x7764002f <+0x0023> b8 01 00 00 00 mov $0x1,%eax
              0x77640034 <+0x0028> c2 10 00 ret $0x10
              0x77640037 <+0x002b> 90 nop

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved