Unsolved Assert : "uint(i) < uint(size())" in file ..\..\include/QtCore ../src/corelib/tools/qstring.h line 879
-
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. -
@samzhcs1 Is ut this line:
qCWarning(maxCol) << "Column Number Limit is 26!";
?
Is maxCol a number or a category? -
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 thatcelListLen
is already initialised to0
, but that only happens before yourwhile
loop, so within any iteration (but the first) of thewhile
loop, you could be using a stalecelListLen
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.
-
@jsulm A category
-
@samzhcs1 Which line exactly causes the warning?
-
@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