/* I have problem with fixing a crash probably involving a copy constructor or an assignment operator. Here's a code snippet that works: QDictIterator it(m_signatures); Q_ASSERT(!it.isEmpty()); for(; it.current(); ++it) kdDebug(26560) << it.current()->stringSynopsis().string() << endl; However, if I change the first line to: QDictIterator it(functionSignatures()); the Q_ASSERT line crashes, inside the isEmpty() call, which more specifically looks like this: bool isEmpty() const { return dict->count() == 0; } The functionSignatures() function has this signature: virtual FunctionSignature::Dict functionSignatures() const; My thought is hence that my SharedDict class is buggy, that something goes wrong when copying the FunctionSignature::Dict object. The SharedDict class is pasted below, and so is the backtrace and valgrind output of the crash. */ --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- template class SharedDict : public QDict { public: SharedDict(int size) : QDict(size) { } SharedDict(const SharedDict & dict) : QDict(dict) { kdDebug(26560) << k_funcinfo << endl; QDictIterator it(dict); for(; it.current(); ++it) it.current()->ref(); } SharedDict() : QDict() { } virtual ~SharedDict() { } virtual void clear() { QDictIterator it(*this); for(; it.current(); ++it) it.current()->deref(); QDict::clear(); } virtual void remove(const QString &key) { T *item = find(key); if(item) item->deref(); QDict::remove(key); } QDict &operator=(const QDict &dict) { kdDebug(26560) << k_funcinfo << endl; QDictIterator it(dict); for(; it.current(); ++it) it.current()->ref(); QDict::operator=(dict); return *this; } QDict &operator+=(const QDict &dict) { QDictIterator it(dict); for(; it.current(); ++it) insert(it.currentKey(), it.current()); return *this; } virtual void insert(const QString &key, const T *item) { Q_ASSERT(item); const_cast(item)->ref(); QDict::insert(key, item); } virtual void insert(const DOMString &key, const T *item) { QDict::insert(key.string(), item); } virtual T *find(const DOMString &key) const { return static_cast(QDict::find(key.string())); } }; --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- /* Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 16384 (LWP 25104)] 0x401f0479 in QDictIterator::isEmpty() const (this=0xbfffeb40) at qdict.h:107 107 bool isEmpty() const { return dict->count() == 0; } #0 0x401f0479 in QDictIterator::isEmpty() const (this=0xbfffeb40) at qdict.h:107 #1 0x401ee3a2 in SystemFunctionFactory (this=0x815ddf8) at SystemFunctionFactory.cpp:187 ----- SystemFunctionFactory.cpp:187 is the "Q_ASSERT(!it.isEmpty());" line */ --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- /* ==25125== ==25125== Invalid read of size 4 ==25125== at 0x1BAE1479: QDictIterator::isEmpty() const (qdict.h:107) ==25125== by 0x1BADF3A1: SystemFunctionFactory::SystemFunctionFactory() (SystemFunctionFactory.cpp:187) [...] ==25125== Address 0x0 is not stack'd, malloc'd or (recently) free'd */ ---------------------------------------------------------------------------------