From 3bb0cf4ad7166860fb7b81b1bbe1d84d86d4203c Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@nokia.com>
Date: Fri, 22 Oct 2010 15:27:11 +0200
Subject: Fix access to uninitialised memory in case of new throwing

Testing will come later with a full test for exception issues

Task-number: QTBUG-14637
Reviewed-by: Olivier Goffart
---
 src/corelib/tools/qsharedpointer_impl.h | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 4cce339..2519a22 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -378,6 +378,13 @@ namespace QtSharedPointer {
 
         inline ExternalRefCount() : d(0) { }
         inline ExternalRefCount(Qt::Initialization i) : Basic<T>(i) { }
+
+        inline ExternalRefCount(T *ptr) : Basic<T>(Qt::Uninitialized) // throws
+        { internalConstruct(ptr); }
+        template <typename Deleter>
+        inline ExternalRefCount(T *ptr, Deleter d) : Basic<T>(Qt::Uninitialized) // throws
+        { internalConstruct(ptr, d); }
+
         inline ExternalRefCount(const ExternalRefCount<T> &other) : Basic<T>(other), d(other.d)
         { if (d) ref(); }
         template <class X>
@@ -448,11 +455,12 @@ public:
     inline QSharedPointer() { }
     // inline ~QSharedPointer() { }
 
-    inline explicit QSharedPointer(T *ptr) : BaseClass(Qt::Uninitialized)
-    { BaseClass::internalConstruct(ptr); }
+    inline explicit QSharedPointer(T *ptr) : BaseClass(ptr) // throws
+    { }
 
     template <typename Deleter>
-    inline QSharedPointer(T *ptr, Deleter d) { BaseClass::internalConstruct(ptr, d); }
+    inline QSharedPointer(T *ptr, Deleter d) : BaseClass(ptr, d) // throws
+    { }
 
     inline QSharedPointer(const QSharedPointer<T> &other) : BaseClass(other) { }
     inline QSharedPointer<T> &operator=(const QSharedPointer<T> &other)
-- 
cgit v0.12


From bdef6d2613b424dffd49ce1bced8213670aec1e9 Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@nokia.com>
Date: Sun, 24 Oct 2010 00:02:38 +0200
Subject: Fix warning introduced by last commit on hiding of the 'd' member

qsharedpointer_impl.h: In constructor 'QtSharedPointer::ExternalRefCount<T>::ExternalRefCount(T*, Deleter)':
qsharedpointer_impl.h:385: warning: declaration of 'd' shadows a member of 'this'
---
 src/corelib/tools/qsharedpointer_impl.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 2519a22..2895bba 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -382,8 +382,8 @@ namespace QtSharedPointer {
         inline ExternalRefCount(T *ptr) : Basic<T>(Qt::Uninitialized) // throws
         { internalConstruct(ptr); }
         template <typename Deleter>
-        inline ExternalRefCount(T *ptr, Deleter d) : Basic<T>(Qt::Uninitialized) // throws
-        { internalConstruct(ptr, d); }
+        inline ExternalRefCount(T *ptr, Deleter deleter) : Basic<T>(Qt::Uninitialized) // throws
+        { internalConstruct(ptr, deleter); }
 
         inline ExternalRefCount(const ExternalRefCount<T> &other) : Basic<T>(other), d(other.d)
         { if (d) ref(); }
-- 
cgit v0.12