From 02e448784543df2d81135ac583c39df6237dac69 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 10 Apr 2015 23:18:23 -0700 Subject: Correct calculation of filesystem data on unusual filesystems POSIX.1 says f_blocks, f_bfree, f_bavail are calculated in terms of f_frsize, not of the regular block size f_bsize. On most systems, it's the same, which is why we didn't catch it. I don't have any filesystem to test this on to confirm. Reference: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_statvfs.h.html Task-number: QTBUG-45137 Change-Id: I27eaacb532114dd188c4ffff13d3e13016bed4e6 Reviewed-by: Dmitry Shachnev Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Ivan Komissarov --- src/corelib/io/qstorageinfo_unix.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index 2a83e87b0c..cd3c60650e 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -416,9 +416,9 @@ void QStorageInfoPrivate::retreiveVolumeInfo() valid = true; ready = true; - bytesTotal = statfs_buf.f_blocks * statfs_buf.f_bsize; - bytesFree = statfs_buf.f_bfree * statfs_buf.f_bsize; - bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_bsize; + bytesTotal = statfs_buf.f_blocks * statfs_buf.f_frsize; + bytesFree = statfs_buf.f_bfree * statfs_buf.f_frsize; + bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize; #if defined(Q_OS_ANDROID) #if defined(_STATFS_F_FLAGS) readOnly = (statfs_buf.f_flags & ST_RDONLY) != 0; -- cgit v1.2.3 From 18a3b431678e3b456c33a9f7ae21d8653dd2ef85 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 27 Apr 2015 01:22:36 +0200 Subject: Update QProcess doc to use non-deprecated setProcessEnvironment Currently the documentation still mentions the use of the deprected setEnvironment function. This patch aims to correct that Task-number: QTBUG-45235 Change-Id: Iab35754b39f025c7493a6f061eb72e23bc4cf308 Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index baba9a0f9e..4d2a75c0fa 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -373,8 +373,8 @@ QString QProcessEnvironment::value(const QString &name, const QString &defaultVa Use with the QProcess::setEnvironment function is not recommended due to potential encoding problems under Unix, and worse performance. - \sa systemEnvironment(), QProcess::systemEnvironment(), QProcess::environment(), - QProcess::setEnvironment() + \sa systemEnvironment(), QProcess::systemEnvironment(), + QProcess::setProcessEnvironment() */ QStringList QProcessEnvironment::toStringList() const { @@ -534,7 +534,7 @@ void QProcessPrivate::Channel::clear() Certain processes need special environment settings in order to operate. You can set environment variables for your process by - calling setEnvironment(). To set a working directory, call + calling setProcessEnvironment(). To set a working directory, call setWorkingDirectory(). By default, processes are run in the current working directory of the calling process. @@ -2471,7 +2471,7 @@ QT_END_INCLUDE_NAMESPACE \note For new code, it is recommended to use QProcessEnvironment::systemEnvironment() - \sa QProcessEnvironment::systemEnvironment(), environment(), setEnvironment() + \sa QProcessEnvironment::systemEnvironment(), setProcessEnvironment() */ QStringList QProcess::systemEnvironment() { -- cgit v1.2.3 From 2cb17c1fb903434274e58692c9f0df619affdab0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 18 May 2015 11:29:31 +0200 Subject: Improve documentation for Qt::ItemNeverHasChildren. Change-Id: Ied817314d6e72f08a81138bd817c8570d586fa30 Reviewed-by: Oswald Buddenhagen Reviewed-by: David Faure Reviewed-by: Martin Smith Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/global/qnamespace.qdoc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/corelib') diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 3f9526c788..87056b79f0 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2562,6 +2562,7 @@ \value ItemIsEnabled The user can interact with the item. \value ItemIsTristate The item is checkable with three separate states. \value ItemNeverHasChildren The item never has child items. + This is used for optimization purposes only. Note that checkable items need to be given both a suitable set of flags and an initial state, indicating whether the item is checked or not. -- cgit v1.2.3 From d82d5b1c43b270ef6f4f0d90ce5d7d96ea0b7a97 Mon Sep 17 00:00:00 2001 From: Mikhail Lappo Date: Wed, 3 Jun 2015 10:09:42 +0300 Subject: Check for integer overflows in places where qAllocMore is used Task-number: QTBUG-41230 Change-Id: Ic2167364e326092482657f2d2b4ab6ad3e5af631 (partially cherry-picked from 880986be2357a1f80827d038d770dc2f80300201) Reviewed-by: Thiago Macieira --- src/corelib/tools/qarraydata.cpp | 16 ++++++++++++++-- src/corelib/tools/qbytearray.cpp | 7 +++++-- src/corelib/tools/qlist.cpp | 2 ++ src/corelib/tools/qstring.cpp | 5 ++++- src/corelib/tools/qtools_p.h | 6 ++++++ 5 files changed, 31 insertions(+), 5 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 98c484c1dd..d060ff84f2 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -85,8 +85,20 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, headerSize += (alignment - Q_ALIGNOF(QArrayData)); // Allocate additional space if array is growing - if (options & Grow) - capacity = qAllocMore(int(objectSize * capacity), int(headerSize)) / int(objectSize); + if (options & Grow) { + + // Guard against integer overflow when multiplying. + if (capacity > std::numeric_limits::max() / objectSize) + return 0; + + size_t alloc = objectSize * capacity; + + // Make sure qAllocMore won't overflow. + if (headerSize > size_t(MaxAllocSize) || alloc > size_t(MaxAllocSize) - headerSize) + return 0; + + capacity = qAllocMore(int(alloc), int(headerSize)) / int(objectSize); + } size_t allocSize = headerSize + objectSize * capacity; diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 5ec8c317e8..1e87f7b023 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -64,7 +64,7 @@ int qFindByteArray( int qAllocMore(int alloc, int extra) Q_DECL_NOTHROW { Q_ASSERT(alloc >= 0 && extra >= 0); - Q_ASSERT_X(uint(alloc) < QByteArray::MaxSize, "qAllocMore", "Requested size is too large!"); + Q_ASSERT_X(alloc <= MaxAllocSize - extra, "qAllocMore", "Requested size is too large!"); unsigned nalloc = qNextPowerOfTwo(alloc + extra); @@ -1495,8 +1495,11 @@ void QByteArray::reallocData(uint alloc, Data::AllocationOptions options) Data::deallocate(d); d = x; } else { - if (options & Data::Grow) + if (options & Data::Grow) { + if (alloc > uint(MaxAllocSize) - uint(sizeof(Data))) + qBadAlloc(); alloc = qAllocMore(alloc, sizeof(Data)); + } Data *x = static_cast(::realloc(d, sizeof(Data) + alloc)); Q_CHECK_PTR(x); x->alloc = alloc; diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index fe5e0f33b4..b91fd38a5f 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -55,6 +55,8 @@ const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0 static int grow(int size) { + if (size_t(size) > (MaxAllocSize - QListData::DataHeaderSize) / sizeof(void *)) + qBadAlloc(); // dear compiler: don't optimize me out. volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *); return x; diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 189caf8bd7..96f3c4147c 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1656,8 +1656,11 @@ void QString::resize(int size) void QString::reallocData(uint alloc, bool grow) { - if (grow) + if (grow) { + if (alloc > (uint(MaxAllocSize) - sizeof(Data)) / sizeof(QChar)) + qBadAlloc(); alloc = qAllocMore(alloc * sizeof(QChar), sizeof(Data)) / sizeof(QChar); + } if (d->ref.isShared() || IS_RAW_DATA(d)) { Data::AllocationOptions allocOptions(d->capacityReserved ? Data::CapacityReserved : 0); diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h index 3876d3822c..1e72db1d87 100644 --- a/src/corelib/tools/qtools_p.h +++ b/src/corelib/tools/qtools_p.h @@ -46,9 +46,15 @@ // #include "QtCore/qglobal.h" +#include QT_BEGIN_NAMESPACE +// We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size. +enum { + MaxAllocSize = (1 << (std::numeric_limits::digits - 1)) - 1 +}; + // implemented in qbytearray.cpp int Q_CORE_EXPORT qAllocMore(int alloc, int extra) Q_DECL_NOTHROW; -- cgit v1.2.3 From 40cbf1927bdd2fa9f531a047d1ba66f68c35d170 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 10 Jun 2015 07:42:42 -0700 Subject: Don't add qmutex_xxx.cpp to SOURCES, as qmutex.cpp #include's them Normally qmake catches the #include and drops the source from SOURCES. But the parser has bugs, so help it by never adding the files. The false: SOURCES += is left so that the sources can be found by Qt Creator. Task-number: QTBUG-46582 Change-Id: I049a653beeb5454c9539ffff13e667877350346b Reviewed-by: Jake Petroules --- src/corelib/thread/thread.pri | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/thread/thread.pri b/src/corelib/thread/thread.pri index 3c1ddd984a..2cb00a6cf4 100644 --- a/src/corelib/thread/thread.pri +++ b/src/corelib/thread/thread.pri @@ -46,21 +46,21 @@ SOURCES += thread/qatomic.cpp \ unix:SOURCES += thread/qthread_unix.cpp \ thread/qwaitcondition_unix.cpp -win32:SOURCES += thread/qmutex_win.cpp \ - thread/qthread_win.cpp \ +win32:SOURCES += thread/qthread_win.cpp \ thread/qwaitcondition_win.cpp -integrity:SOURCES += thread/qmutex_unix.cpp \ - thread/qthread_unix.cpp \ +integrity:SOURCES += thread/qthread_unix.cpp \ thread/qwaitcondition_unix.cpp -unix: { - mac { - SOURCES += thread/qmutex_mac.cpp - } else:linux-*:!linux-lsb-* { - SOURCES += thread/qmutex_linux.cpp - } else { - SOURCES += thread/qmutex_unix.cpp - } +false { + # files #included by others, but listed here so IDEs parsing this file know + # they are part of QtCore. Usually, qmake can find out that certain files + # are #included by others and thus remove from SOURCES, but it gets lost + # with qmutex.cpp. + SOURCES += \ + thread/qmutex_linux.cpp \ + thread/qmutex_mac.cpp \ + thread/qmutex_unix.cpp \ + thread/qmutex_win.cpp } -- cgit v1.2.3 From 24dc5973868358d56afb375cc01c5db7d06c9fbd Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Wed, 24 Jun 2015 11:41:16 +0200 Subject: Add reference to QRegularExpression Currently there's no mention of QRegularExpression in QRegExp's documentation. This makes it hard to find QRegularExpression for user used to QRegExp. This patch adds that missing reference. Task-number: QTBUG-46816 Change-Id: If3a981d5759fbed3eecd07e046882e6da378cc4e Reviewed-by: Oswald Buddenhagen Reviewed-by: Sze Howe Koh --- src/corelib/tools/qregexp.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index cd8c393d51..f896828e2e 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -115,6 +115,10 @@ int qFindString(const QChar *haystack, int haystackLen, int from, A good text on regexps is \e {Mastering Regular Expressions} (Third Edition) by Jeffrey E. F. Friedl, ISBN 0-596-52812-4. + \note In Qt 5, the new QRegularExpression class provides a Perl + compatible implementation of regular expressions and is recommended + in place of QRegExp. + \tableofcontents \section1 Introduction -- cgit v1.2.3 From 925822eca54d98ea4da73ea75387393e76dbcdda Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sun, 2 Aug 2015 01:50:33 +0200 Subject: QProcessEnvironment documentation typo fix Task-number: QTBUG-45985 Change-Id: I42de961ca6d57847c135abd8395494d0e416ab05 Reviewed-by: Sze Howe Koh --- src/corelib/io/qprocess.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 914774b433..af80f4f281 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -127,7 +127,7 @@ QT_BEGIN_NAMESPACE Unix environment allows both variable names and contents to contain arbitrary binary data (except for the NUL character). QProcessEnvironment will preserve such variables, but does not support manipulating variables whose names or - values are not encodable by the current locale settings (see + values cannot be encoded by the current locale settings (see QTextCodec::codecForLocale). On Windows, the variable names are case-insensitive, but case-preserving. @@ -528,7 +528,7 @@ void QProcessPrivate::Channel::clear() QProcess can merge the two output channels, so that standard output and standard error data from the running process both use the standard output channel. Call setProcessChannelMode() with - MergedChannels before starting the process to activative + MergedChannels before starting the process to activate this feature. You also have the option of forwarding the output of the running process to the calling, main process, by passing ForwardedChannels as the argument. It is also possible to forward @@ -1266,7 +1266,7 @@ QProcess::InputChannelMode QProcess::inputChannelMode() const /*! \since 5.2 - Sets the channel mode of the QProcess standard intput + Sets the channel mode of the QProcess standard input channel to the \a mode specified. This mode will be used the next time start() is called. @@ -2311,7 +2311,7 @@ void QProcess::setArguments(const QStringList &arguments) The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc). - On Windows, terminate() posts a WM_CLOSE message to all toplevel windows + On Windows, terminate() posts a WM_CLOSE message to all top-level windows of the process and then to the main thread of the process itself. On Unix and OS X the \c SIGTERM signal is sent. @@ -2507,7 +2507,7 @@ QT_END_INCLUDE_NAMESPACE This function does not cache the system environment. Therefore, it's possible to obtain an updated version of the environment if low-level C - library functions like \tt setenv ot \tt putenv have been called. + library functions like \tt setenv or \tt putenv have been called. However, note that repeated calls to this function will recreate the list of environment variables, which is a non-trivial operation. @@ -2537,7 +2537,7 @@ QStringList QProcess::systemEnvironment() It is returned as a QProcessEnvironment. This function does not cache the system environment. Therefore, it's possible to obtain an updated version of the environment if low-level C library - functions like \tt setenv ot \tt putenv have been called. + functions like \tt setenv or \tt putenv have been called. However, note that repeated calls to this function will recreate the QProcessEnvironment object, which is a non-trivial operation. -- cgit v1.2.3 From 64b53ddf560b790fe4f98bcfc2329293cdc7483e Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 3 Aug 2015 00:37:30 +0200 Subject: Doc: add clarification about signals not being buffered when blocked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-15238 Change-Id: Id762007415245f104ffe5cdfd100889f9a73ae95 Reviewed-by: Leena Miettinen Reviewed-by: Topi Reiniö --- src/corelib/kernel/qobject.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 6bc4d7e7ed..bcc4e7f8e6 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1385,6 +1385,8 @@ bool QObject::eventFilter(QObject * /* watched */, QEvent * /* event */) Note that the destroyed() signal will be emitted even if the signals for this object have been blocked. + Signals emitted while being blocked are not buffered. + \sa signalsBlocked() */ -- cgit v1.2.3 From 141f03a814245e33a1e30d89429dc92783c227bd Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 3 Aug 2015 01:13:07 +0200 Subject: Doc: mark private QChar constructors as internal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-39862 Change-Id: Ie0d533e3897200589248c803069c41661b15997e Reviewed-by: Sze Howe Koh Reviewed-by: Topi Reiniö --- src/corelib/tools/qchar.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 5c094772b8..1bf0aa0dec 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -595,12 +595,14 @@ QT_BEGIN_NAMESPACE /*! \fn QChar::QChar(char ch) + \internal Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. */ /*! \fn QChar::QChar(uchar ch) + \internal Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. */ -- cgit v1.2.3 From 34130b9caf001682f1decb6ba69b80657b814ed0 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 27 Jul 2015 00:22:11 +0200 Subject: QMimeDatabase: use QElapsedTimer instead of QDateTime::currentDateTime() This reduces the number of syscalls greatly, by avoiding the timezone conversion every time. Change-Id: I39a54def4b45f25c6e037ced6943b05ddc749c9d Reviewed-by: Milian Wolff --- src/corelib/mimetypes/qmimeprovider.cpp | 5 ++--- src/corelib/mimetypes/qmimeprovider_p.h | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index 7342a5cd77..1ab1a44392 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -79,10 +79,9 @@ Q_CORE_EXPORT int qmime_secondsBetweenChecks = 5; // exported for the unit test bool QMimeProviderBase::shouldCheck() { - const QDateTime now = QDateTime::currentDateTime(); - if (m_lastCheck.isValid() && m_lastCheck.secsTo(now) < qmime_secondsBetweenChecks) + if (m_lastCheck.isValid() && m_lastCheck.elapsed() < qmime_secondsBetweenChecks * 1000) return false; - m_lastCheck = now; + m_lastCheck.start(); return true; } diff --git a/src/corelib/mimetypes/qmimeprovider_p.h b/src/corelib/mimetypes/qmimeprovider_p.h index 5a89ac23c3..eaf95942f7 100644 --- a/src/corelib/mimetypes/qmimeprovider_p.h +++ b/src/corelib/mimetypes/qmimeprovider_p.h @@ -51,6 +51,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -77,7 +78,7 @@ public: QMimeDatabasePrivate *m_db; protected: bool shouldCheck(); - QDateTime m_lastCheck; + QElapsedTimer m_lastCheck; }; /* -- cgit v1.2.3 From af3152adee2de79c03c0926400e920122b669c4d Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Mon, 13 Jul 2015 15:42:35 +0200 Subject: QMimeProvider: Do not crash when globPatterns is empty. Change-Id: I351a533a1f03ac2e7bdec876b657a80fac60b2ed Reviewed-by: Milian Wolff --- src/corelib/mimetypes/qmimeprovider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index 1ab1a44392..dab5bb81c9 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -624,7 +624,7 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) // Let's assume that shared-mime-info is at least version 0.70 // Otherwise we would need 1) a version check, and 2) code for parsing patterns from the globs file. #if 1 - if (!mainPattern.isEmpty() && data.globPatterns.first() != mainPattern) { + if (!mainPattern.isEmpty() && (data.globPatterns.isEmpty() || data.globPatterns.first() != mainPattern)) { // ensure it's first in the list of patterns data.globPatterns.removeAll(mainPattern); data.globPatterns.prepend(mainPattern); -- cgit v1.2.3 From e3d7cf7c96964f9d55116f235dc3e0cbf5fef971 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Sat, 8 Aug 2015 21:07:58 +0100 Subject: Cocoa: fix integer multiplication overflow in qt_gettime() Task-number: QTBUG-24031 Change-Id: Iae00b10b6a7423508669ef173a80a03b3dd388c6 Reviewed-by: Thiago Macieira --- src/corelib/tools/qelapsedtimer_mac.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qelapsedtimer_mac.cpp b/src/corelib/tools/qelapsedtimer_mac.cpp index a355bf03e8..e946ac096f 100644 --- a/src/corelib/tools/qelapsedtimer_mac.cpp +++ b/src/corelib/tools/qelapsedtimer_mac.cpp @@ -59,8 +59,13 @@ static qint64 absoluteToNSecs(qint64 cpuTime) { if (info.denom == 0) mach_timebase_info(&info); +#ifdef __LP64__ + __uint128_t nsecs = static_cast<__uint128_t>(cpuTime) * info.numer / info.denom; + return static_cast(nsecs); +#else qint64 nsecs = cpuTime * info.numer / info.denom; return nsecs; +#endif } static qint64 absoluteToMSecs(qint64 cpuTime) -- cgit v1.2.3 From 314c83c0c2f91532654f869b7dc6af1b7e8538da Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 31 Jul 2015 22:55:55 +0200 Subject: Do not use Q_GLOBAL_STATIC in the implementation of QMutex Since Q_GLOBAL_STATIC might use QMutex and cause a stack overflow. Task-number: QTBUG-47554 Change-Id: I4853c5e9b9168d4a417200e2a45a1bf9cb103a30 Reviewed-by: David Faure Reviewed-by: Pierre Rossi Reviewed-by: Thiago Macieira --- src/corelib/thread/qmutex.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 002a9cc7bc..3269ee3ae8 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -563,7 +563,28 @@ const int FreeListConstants::Sizes[FreeListConstants::BlockCount] = { }; typedef QFreeList FreeList; -Q_GLOBAL_STATIC(FreeList, freelist); +// We cannot use Q_GLOBAL_STATIC because it uses QMutex +#if defined(Q_COMPILER_THREADSAFE_STATICS) +FreeList *freelist() +{ + static FreeList list; + return &list; +} +#else +FreeList *freelist() +{ + static QAtomicPointer list; + FreeList *local = list.loadAcquire(); + if (!local) { + local = new FreeList; + if (!list.testAndSetRelease(0, local)) { + delete local; + local = list.loadAcquire(); + } + } + return local; +} +#endif } QMutexPrivate *QMutexPrivate::allocate() -- cgit v1.2.3 From 40a4105faef14268410b3ab4ae432f386c74d0e2 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Wed, 12 Aug 2015 17:00:49 +0200 Subject: Fix QChar char constructors documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reverts the wrongly added \internal and adds a warning for users that the constructors will not be available if QT_NO_CAST_FROM_ASCII is defined Task-number: QTBUG-39862 Change-Id: I038eea3f4eef0b914b470309a2f515741eec35a9 Reviewed-by: Topi Reiniö Reviewed-by: Sze Howe Koh --- src/corelib/tools/qchar.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 1bf0aa0dec..014d91162a 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -595,16 +595,24 @@ QT_BEGIN_NAMESPACE /*! \fn QChar::QChar(char ch) - \internal Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. + + \note This constructor is not available when \c QT_NO_CAST_FROM_ASCII + is defined. + + \sa QT_NO_CAST_FROM_ASCII */ /*! \fn QChar::QChar(uchar ch) - \internal Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. + + \note This constructor is not available when \c QT_NO_CAST_FROM_ASCII + is defined. + + \sa QT_NO_CAST_FROM_ASCII */ /*! -- cgit v1.2.3 From 1ff66a79626d40a8379a639a0fae3696fc7a06c0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 18 Feb 2015 12:36:47 -0800 Subject: QProcess: Ensure that the stdin buffer is cleared on start() The buffer may have been left dirty if we were unable to write all the data to the child process in the previous run. So ensure we clear it before starting a new one. We already did that for stdout and stderr, for some reason. Task-number: QTBUG-44517 Change-Id: I1a800c709d3543699131ffff13c419da3bbffacf Reviewed-by: Kai Koehne Reviewed-by: Joerg Bornemann Reviewed-by: Thiago Macieira Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess.cpp | 3 ++- src/corelib/io/qwindowspipewriter.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 176386d6df..c29b97b535 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2014 Intel Corporation +** Copyright (C) 2015 Intel Corporation ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -2135,6 +2135,7 @@ void QProcessPrivate::start(QIODevice::OpenMode mode) qDebug() << "QProcess::start(" << program << ',' << arguments << ',' << mode << ')'; #endif + stdinChannel.buffer.clear(); stdoutChannel.buffer.clear(); stderrChannel.buffer.clear(); diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp index add2ac94da..57053f129a 100644 --- a/src/corelib/io/qwindowspipewriter.cpp +++ b/src/corelib/io/qwindowspipewriter.cpp @@ -85,7 +85,7 @@ qint64 QWindowsPipeWriter::write(const char *ptr, qint64 maxlen) return -1; QMutexLocker locker(&lock); - data.append(QByteArray(ptr, maxlen)); + data.append(ptr, maxlen); waitCondition.wakeOne(); return maxlen; } -- cgit v1.2.3 From 4ccf5c6f4a411d367749565323f7c7fd469b025e Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 13 Aug 2015 23:51:34 +0200 Subject: QMimeDatabase: adapt to changes in shared-mime-info 1.3 The generated xml file is now lowercase. This was changed in shared-mime-info 3805d0bcf2. It led to runtime warnings "No file found for ...", which helped notice the bug. Change-Id: I31f0fc7f0fe8a098c3f79c0bcbeeb1909d2cc05a Reviewed-by: Thiago Macieira --- src/corelib/mimetypes/qmimeprovider.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index dab5bb81c9..887db51e5c 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -560,10 +560,13 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) // load comment and globPatterns const QString file = data.name + QLatin1String(".xml"); - const QStringList mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file); + // shared-mime-info since 1.3 lowercases the xml files + QStringList mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file.toLower()); if (mimeFiles.isEmpty()) { - // TODO: ask Thiago about this - qWarning() << "No file found for" << file << ", even though the file appeared in a directory listing."; + mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file); // pre-1.3 + } + if (mimeFiles.isEmpty()) { + qWarning() << "No file found for" << file << ", even though update-mime-info said it would exist."; qWarning() << "Either it was just removed, or the directory doesn't have executable permission..."; qWarning() << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime"), QStandardPaths::LocateDirectory); return; -- cgit v1.2.3 From 507625d984f9467b056e603560d62a2e4a56074d Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 28 Jul 2015 13:43:54 +0200 Subject: fix assertion in QProcess/Win Do not call bytesAvailableInChannel if the source pipe end is invalid. This is the case when redirecting channels on Windows. The assertions in bytesAvailableInChannel were triggered whenever an output process or output file was set and waitForBytesWritten was called. Task-number: QTBUG-45548 Change-Id: I225dfea2c5e27e122f75008a3a06d425554e00fe Reviewed-by: Alex Trotsenko Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess_win.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index cef961ecbd..eb88ded2c9 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -704,13 +704,15 @@ bool QProcessPrivate::waitForBytesWritten(int msecs) return true; // If we wouldn't write anything, check if we can read stdout. - if (bytesAvailableInChannel(&stdoutChannel) != 0) { + if (stdoutChannel.pipe[0] != INVALID_Q_PIPE + && bytesAvailableInChannel(&stdoutChannel) != 0) { tryReadFromChannel(&stdoutChannel); timer.resetIncrements(); } // Check if we can read stderr. - if (bytesAvailableInChannel(&stderrChannel) != 0) { + if (stderrChannel.pipe[0] != INVALID_Q_PIPE + && bytesAvailableInChannel(&stderrChannel) != 0) { tryReadFromChannel(&stderrChannel); timer.resetIncrements(); } -- cgit v1.2.3 From ee15bef3ea24a78e5fd4708c0a1cebee2e4fac5d Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 17 Aug 2015 11:28:16 +0200 Subject: QRegularExpression: fix matching over QStringRefs Playing with the offset argument of pcre_exec is not equivalent to adjusting the pointer to the subject string. In particular, PCRE can go behind the offset to check for lookbehinds or "transition" metacharacters (\b, \B, etc.). This made the code that deals with QStringRefs not matching in behavior with the corresponding code dealing with QStrings. For instance, QString subject("Miss"); QRegularExpression re("(?<=M)iss"); re.match(subject.mid(1)); // doesn't match re.match(subject.midRef(1)); // matches!!! Instead, actually adjust the pointer to the subject string so that the behavior is identical. A broken test that relied on the equivalence is also removed. Change-Id: If96333241ef59621d7f5a6a170ebd0a186844874 Reviewed-by: Volker Krause Reviewed-by: Thiago Macieira --- src/corelib/tools/qregularexpression.cpp | 45 +++++++++++++++----------------- 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index 2e3c2ca79f..070e68154f 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2012 Giuseppe D'Angelo . -** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo +** Copyright (C) 2015 Giuseppe D'Angelo . +** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo ** Copyright (C) 2015 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** @@ -1325,48 +1325,45 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString int * const captureOffsets = priv->capturedOffsets.data(); const int captureOffsetsCount = priv->capturedOffsets.size(); - int realOffset = offset + subjectStart; - const int realSubjectLength = subjectLength + subjectStart; - - const unsigned short * const subjectUtf16 = subject.utf16(); + const unsigned short * const subjectUtf16 = subject.utf16() + subjectStart; int result; if (!previousMatchWasEmpty) { result = pcre16SafeExec(compiledPattern, currentStudyData, - subjectUtf16, realSubjectLength, - realOffset, pcreOptions, + subjectUtf16, subjectLength, + offset, pcreOptions, captureOffsets, captureOffsetsCount); } else { result = pcre16SafeExec(compiledPattern, currentStudyData, - subjectUtf16, realSubjectLength, - realOffset, pcreOptions | PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED, + subjectUtf16, subjectLength, + offset, pcreOptions | PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED, captureOffsets, captureOffsetsCount); if (result == PCRE_ERROR_NOMATCH) { - ++realOffset; + ++offset; if (usingCrLfNewlines - && realOffset < realSubjectLength - && subjectUtf16[realOffset - 1] == QLatin1Char('\r') - && subjectUtf16[realOffset] == QLatin1Char('\n')) { - ++realOffset; - } else if (realOffset < realSubjectLength - && QChar::isLowSurrogate(subjectUtf16[realOffset])) { - ++realOffset; + && offset < subjectLength + && subjectUtf16[offset - 1] == QLatin1Char('\r') + && subjectUtf16[offset] == QLatin1Char('\n')) { + ++offset; + } else if (offset < subjectLength + && QChar::isLowSurrogate(subjectUtf16[offset])) { + ++offset; } result = pcre16SafeExec(compiledPattern, currentStudyData, - subjectUtf16, realSubjectLength, - realOffset, pcreOptions, + subjectUtf16, subjectLength, + offset, pcreOptions, captureOffsets, captureOffsetsCount); } } #ifdef QREGULAREXPRESSION_DEBUG qDebug() << "Matching" << pattern << "against" << subject - << "starting at" << subjectStart << "len" << subjectLength << "real len" << realSubjectLength - << "offset" << offset << "real offset" << realOffset + << "starting at" << subjectStart << "len" << subjectLength + << "offset" << offset << matchType << matchOptions << previousMatchWasEmpty << "result" << result; #endif @@ -2041,7 +2038,7 @@ QString QRegularExpressionMatch::captured(int nth) const if (start == -1) // didn't capture return QString(); - return d->subject.mid(start, capturedLength(nth)); + return d->subject.mid(start + d->subjectStart, capturedLength(nth)); } /*! @@ -2062,7 +2059,7 @@ QStringRef QRegularExpressionMatch::capturedRef(int nth) const if (start == -1) // didn't capture return QStringRef(); - return d->subject.midRef(start, capturedLength(nth)); + return d->subject.midRef(start + d->subjectStart, capturedLength(nth)); } /*! -- cgit v1.2.3 From cc5e84c8788a6d6f05dfdf76fc249177ee74dce1 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 11 Aug 2015 09:59:10 -0700 Subject: Avoid overflow in QTime::addSecs with too big a number of seconds QDateTime::addSecs needs to do something similar, but not identical because it needs the number of days too. And then there are daylight savings transitions... Task-number: QTBUG-47717 Change-Id: I7de033f80b0e4431b7f1ffff13f976f4f5e5a059 Reviewed-by: Allan Sandfeld Jensen --- src/corelib/tools/qdatetime.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index e445055e1d..eb4eff32b4 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -1681,6 +1681,7 @@ bool QTime::setHMS(int h, int m, int s, int ms) QTime QTime::addSecs(int s) const { + s %= SECS_PER_DAY; return addMSecs(s * 1000); } -- cgit v1.2.3 From ffbc2d3dc06017959167feecd60b66891c3b2c7b Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 19 Aug 2015 14:56:08 +0200 Subject: Doc: Mention Windows limitations in QFileInfo permission methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The limitation is already mentioned in the class documentation, but IMO is severe enough to be highlighted in the documentation of the respective methods, too. Change-Id: I16c68eb41ab9d3a7698d7ef06f747cfd98a8aaff Reviewed-by: Oswald Buddenhagen Reviewed-by: Topi Reiniö --- src/corelib/io/qfileinfo.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 8a86ec5858..51b39b1114 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -263,6 +263,7 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) groupId(). You can examine a file's permissions and ownership in a single statement using the permission() function. + \target NTFS permissions \note On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line: @@ -893,6 +894,9 @@ QDir QFileInfo::absoluteDir() const /*! Returns \c true if the user can read the file; otherwise returns \c false. + \note If the \l{NTFS permissions} check has not been enabled, the result + on Windows will merely reflect whether the file exists. + \sa isWritable(), isExecutable(), permission() */ bool QFileInfo::isReadable() const @@ -911,6 +915,9 @@ bool QFileInfo::isReadable() const /*! Returns \c true if the user can write to the file; otherwise returns \c false. + \note If the \l{NTFS permissions} check has not been enabled, the result on + Windows will merely reflect whether the file is marked as Read Only. + \sa isReadable(), isExecutable(), permission() */ bool QFileInfo::isWritable() const @@ -1137,7 +1144,8 @@ QString QFileInfo::readLink() const returned. This function can be time consuming under Unix (in the order of - milliseconds). + milliseconds). On Windows, it will return an empty string unless + the \l{NTFS permissions} check has been enabled. \sa ownerId(), group(), groupId() */ @@ -1217,6 +1225,9 @@ uint QFileInfo::groupId() const On systems where files do not have permissions this function always returns \c true. + \note The result might be inaccurate on Windows if the + \l{NTFS permissions} check has not been enabled. + Example: \snippet code/src_corelib_io_qfileinfo.cpp 10 @@ -1240,6 +1251,9 @@ bool QFileInfo::permission(QFile::Permissions permissions) const /*! Returns the complete OR-ed together combination of QFile::Permissions for the file. + + \note The result might be inaccurate on Windows if the + \l{NTFS permissions} check has not been enabled. */ QFile::Permissions QFileInfo::permissions() const { -- cgit v1.2.3