Details
-
Sub-task
-
Resolution: Done
-
P2: Important
-
None
-
3bb0cf4
Description
If operator new throws, the following code will dereference uninitialised memory:
QSharedPointer<A> ptr(new A);
qsharedpointer_impl.h: In function 'int main(int, char**)': qsharedpointer_impl.h:337: warning: 'a.QSharedPointer<A>::<anonymous>.QtSharedPointer::ExternalRefCount<A>::d' may be used uninitialized in this function main.cpp:16: note: 'a.QSharedPointer<A>::<anonymous>.QtSharedPointer::ExternalRefCount<A>::d' was declared here qsharedpointer_impl.h:340: warning: 'a.QSharedPointer<A>::<anonymous>.QtSharedPointer::ExternalRefCount<A>::<anonymous>.QtSharedPointer::Basic<A>::value' may be used uninitialized in this function
The reason is that QSharedPointer::QSharedPointer(T*) leaves its base uninitialised, then calls a function that may throw (internalConstruct). If that throws, then the parent class's destructor is run, which proceeds to dereference the uninitialised members.