From 746114fb8a1036e5ccec88fe22e9378925d3a34a Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 11 Jun 2010 10:57:21 +0200 Subject: Avoid the incorrect usage of QScopedArrayPointer. Don't allow an array of objects stored as a base class. struct A{int a;}; struct B : public A{int b;}; A *foo = new B[2]; foo[1].a = 0; // crash due to (foo + sizeof(A)) and sizeof(A) != sizeof(B) delete [] foo; Reviewed-by: Olivier Goffart --- src/corelib/tools/qscopedpointer.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index bc76a3b..e972d71 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -54,7 +54,7 @@ struct QScopedPointerDeleter static inline void cleanup(T *pointer) { // Enforce a complete type. - // If you get a compile error here, read the secion on forward declared + // If you get a compile error here, read the section on forward declared // classes in the QScopedPointer documentation. typedef char IsIncompleteType[ sizeof(T) ? 1 : -1 ]; (void) sizeof(IsIncompleteType); @@ -69,7 +69,7 @@ struct QScopedPointerArrayDeleter static inline void cleanup(T *pointer) { // Enforce a complete type. - // If you get a compile error here, read the secion on forward declared + // If you get a compile error here, read the section on forward declared // classes in the QScopedPointer documentation. typedef char IsIncompleteType[ sizeof(T) ? 1 : -1 ]; (void) sizeof(IsIncompleteType); @@ -186,11 +186,18 @@ template Q_INLINE_TEMPLATE void qSwap(QScopedPointer &p1, QScopedPointer &p2) { p1.swap(p2); } +namespace QtPrivate { + template struct QScopedArrayEnsureSameType; + template struct QScopedArrayEnsureSameType { typedef X* Type; }; + template struct QScopedArrayEnsureSameType { typedef X* Type; }; +} + template > class QScopedArrayPointer : public QScopedPointer { public: - explicit inline QScopedArrayPointer(T *p = 0) + template + explicit inline QScopedArrayPointer(D *p = 0, typename QtPrivate::QScopedArrayEnsureSameType::Type = 0) : QScopedPointer(p) { } @@ -206,6 +213,17 @@ public: } private: + explicit inline QScopedArrayPointer(void *p) { + // Enforce the same type. + + // If you get a compile error here, make sure you declare + // QScopedArrayPointer with the same template type as you pass to the + // constructor. See also the QScopedPointer documentation. + + // Storing a scalar array as a pointer to a different type is not + // allowed and results in undefined behavior. + } + Q_DISABLE_COPY(QScopedArrayPointer) }; -- cgit v0.12 From 5d82a49aeba2a4b2608ea114702920ced97faddf Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 11 Jun 2010 13:17:43 +0200 Subject: Fix compilation: remove spurious semi-colon --- tools/linguist/lupdate/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp index 6e3ab5c..a575192 100644 --- a/tools/linguist/lupdate/main.cpp +++ b/tools/linguist/lupdate/main.cpp @@ -63,7 +63,7 @@ static void printOut(const QString & out) } class LU { - Q_DECLARE_TR_FUNCTIONS(LUpdate); + Q_DECLARE_TR_FUNCTIONS(LUpdate) }; static void recursiveFileInfoList(const QDir &dir, -- cgit v0.12 From 999caa5d5418cde3bf0cb531fe2c1e15da537dd9 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Fri, 11 Jun 2010 13:06:38 +0200 Subject: Adjust handling of library .bundle on Mac QLibrary::isLibrary() returns true for files with the sufix .bundle. But we did not use to determine the proper library within the bundle in that case. Reviewed-by: Fabien Freling Task-number: QTBUG-11217 --- src/corelib/plugin/qlibrary_unix.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index e8f0eae..9ad1c01 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -223,11 +223,15 @@ bool QLibraryPrivate::load_sys() #ifdef Q_OS_MAC if (!pHnd) { - if (CFBundleRef bundle = CFBundleGetBundleWithIdentifier(QCFString(fileName))) { + QByteArray utf8Bundle = fileName.toUtf8(); + QCFType bundleUrl = CFURLCreateFromFileSystemRepresentation(NULL, reinterpret_cast(utf8Bundle.data()), utf8Bundle.length(), true); + QCFType bundle = CFBundleCreate(NULL, bundleUrl); + if(bundle) { QCFType url = CFBundleCopyExecutableURL(bundle); - QCFString str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); - pHnd = dlopen(QFile::encodeName(str), dlFlags); - attempt = str; + char executableFile[FILENAME_MAX]; + CFURLGetFileSystemRepresentation(url, true, reinterpret_cast(executableFile), FILENAME_MAX); + attempt = QString::fromUtf8(executableFile); + pHnd = dlopen(QFile::encodeName(attempt), dlFlags); } } #endif -- cgit v0.12