Bug 155651 - segmentation fault using qt's QPtrList at() method
segmentation fault using qt's QPtrList at() method
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: qt (Show other bugs)
rawhide
All Linux
medium Severity medium
: ---
: ---
Assigned To: Ngo Than
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-04-22 04:50 EDT by Adrian Reber
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-04-28 06:39:27 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Adrian Reber 2005-04-22 04:50:51 EDT
Following code crashes with a segmentation fault:

#include <qstring.h>
#include <qptrlist.h>
class track_info {
  public:

    QString songname;
};

int main() {
        QPtrList < track_info > trk;
        QString test;
        trk.append(new track_info());
        QString *haha = new QString("haha");
        trk.at(1)->songname = haha->utf8();
        return 0;
}

I am using following command to compile it:
gcc qttest.cc  -I/usr/lib/qt-3.3/include -lqt-mt -L/usr/lib/qt-3.3/lib

And gdb says:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208174912 (LWP 13456)]
0x07560177 in QString::setUnicode () from /usr/lib/qt-3.3/lib/libqt-mt.so.3
(gdb)

I think that this is a bug because the documentation
(http://doc.trolltech.com/3.3/qptrlist.html#at) says:

"Returns a pointer to the item at position index in the list, or 0 if the index
is out of range."

I have tested it with qt-3.3.4-0.fc3.0, qt-devel-3.3.3-8 and qt-3.3.4-11
Comment 1 Ngo Than 2005-04-28 06:39:27 EDT
Hm, it seems your test case is broken, the index is out of range in this case
and get a NULL pointer here! it's why it crashes.
Comment 2 Adrian Reber 2005-04-28 07:19:49 EDT
Okay, then I have maybe misunderstood the documentation:

"Returns a pointer to the item at position index in the list, or 0 if the index
is out of range."

I thought it means I get the element at position 0 but maybe it means I get
NULL. If that's the case then it is my fault.

Note You need to log in before you can comment on or make changes to this bug.