From 0e3d6fe4f69955bf98e23a382caf5251e2b47ea0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 17 Feb 2017 00:54:04 +0100 Subject: QVarLengthArray: fix appending an already-contained item Like the lvalue QVector::append() overload, when we reallocate, we need to take a copy of the function's argument because the reference will get stale upon reallocation. Add a test. [ChangeLog][QtCore][QVarLengthArray] Fixed a bug involving appending an item already in the container to the container again. Change-Id: I06eeed6cb383dd5924e47a302bb3d1666d04c8e8 Reviewed-by: Thiago Macieira --- src/corelib/tools/qvarlengtharray.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index bb5ae78d2b..2d3c25a5dd 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -146,15 +146,25 @@ public: T value(int i, const T &defaultValue) const; inline void append(const T &t) { - if (s == a) // i.e. s != 0 + if (s == a) { // i.e. s != 0 + T copy(t); realloc(s, s<<1); - const int idx = s++; - if (QTypeInfo::isComplex) { - new (ptr + idx) T(t); + const int idx = s++; + if (QTypeInfo::isComplex) { + new (ptr + idx) T(std::move(copy)); + } else { + ptr[idx] = std::move(copy); + } } else { - ptr[idx] = t; + const int idx = s++; + if (QTypeInfo::isComplex) { + new (ptr + idx) T(t); + } else { + ptr[idx] = t; + } } } + void append(const T *buf, int size); inline QVarLengthArray &operator<<(const T &t) { append(t); return *this; } -- cgit v1.2.3 From dd7f62059c2ae52b5c05fdbe1b6b5d5fa5bc1b03 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 16 Feb 2017 15:52:00 +0100 Subject: Fix a race in QFreeList The _next variable need the acquire and release fence in next() to synchronize with the equivalent operations in release() (which already have the them) The ordering on the _v[block] is not enough as this does not synchronize the same object. Task-number: QTBUG-58917 Change-Id: I17cc39e6791433348b6227363dbea92bcf03700d Reviewed-by: David Faure Reviewed-by: Thiago Macieira --- src/corelib/tools/qfreelist_p.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qfreelist_p.h b/src/corelib/tools/qfreelist_p.h index c3efc41d62..a8d1132d06 100644 --- a/src/corelib/tools/qfreelist_p.h +++ b/src/corelib/tools/qfreelist_p.h @@ -237,7 +237,7 @@ inline int QFreeList::next() int id, newid, at; ElementType *v; do { - id = _next.load(); + id = _next.loadAcquire(); at = id & ConstantsType::IndexMask; const int block = blockfor(at); @@ -254,7 +254,7 @@ inline int QFreeList::next() } newid = v[at].next.load() | (id & ~ConstantsType::IndexMask); - } while (!_next.testAndSetRelaxed(id, newid)); + } while (!_next.testAndSetRelease(id, newid)); // qDebug("QFreeList::next(): returning %d (_next now %d, serial %d)", // id & ConstantsType::IndexMask, // newid & ConstantsType::IndexMask, -- cgit v1.2.3 From 809cef1732df9f843dc895cfb3f4b3e58646e050 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 21 Feb 2017 21:35:54 +0100 Subject: QTimeZone: do not access static functions through this-> The this pointer cannot be null, so we can't do d->staticFunction while d is a null pointer. This was caught by Clang 3.8's ubsan. Change-Id: I3c0d39b88cca83d827a69ed1544a4412b18ac907 Reviewed-by: Thiago Macieira --- src/corelib/tools/qtimezone.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index 359c2d0bdb..ec2f7c4af6 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -674,9 +674,9 @@ bool QTimeZone::isDaylightTime(const QDateTime &atDateTime) const QTimeZone::OffsetData QTimeZone::offsetData(const QDateTime &forDateTime) const { if (hasTransitions()) - return d->toOffsetData(d->data(forDateTime.toMSecsSinceEpoch())); + return QTimeZonePrivate::toOffsetData(d->data(forDateTime.toMSecsSinceEpoch())); else - return d->invalidOffsetData(); + return QTimeZonePrivate::invalidOffsetData(); } /*! @@ -712,9 +712,9 @@ bool QTimeZone::hasTransitions() const QTimeZone::OffsetData QTimeZone::nextTransition(const QDateTime &afterDateTime) const { if (hasTransitions()) - return d->toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch())); + return QTimeZonePrivate::toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch())); else - return d->invalidOffsetData(); + return QTimeZonePrivate::invalidOffsetData(); } /*! @@ -733,9 +733,9 @@ QTimeZone::OffsetData QTimeZone::nextTransition(const QDateTime &afterDateTime) QTimeZone::OffsetData QTimeZone::previousTransition(const QDateTime &beforeDateTime) const { if (hasTransitions()) - return d->toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch())); + return QTimeZonePrivate::toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch())); else - return d->invalidOffsetData(); + return QTimeZonePrivate::invalidOffsetData(); } /*! @@ -755,7 +755,7 @@ QTimeZone::OffsetDataList QTimeZone::transitions(const QDateTime &fromDateTime, toDateTime.toMSecsSinceEpoch()); list.reserve(plist.count()); for (const QTimeZonePrivate::Data &pdata : plist) - list.append(d->toOffsetData(pdata)); + list.append(QTimeZonePrivate::toOffsetData(pdata)); } return list; } -- cgit v1.2.3 From 2c130701627ea5bc0df9af9c77edfa4d463b5dd1 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 9 Feb 2017 21:50:30 +0100 Subject: Do not delete someone else's QSystemLocale when constructing another The QSystemLocale constructor remembers the most-recently-constructed instance - a dodgy enough proposition at the best of times - and shares it with much of the rest of QLocale. There is a global static instance, actually of a derived singleton class, to which it is usually set on program start-up. However, the constructor deleted the remembered instance before remembering any new instances; there was no way this could not lead to bad consequences. So let's not do that. Change-Id: Ie8f3d655c9d4f75f6ec00a5861d98d6020ecc633 Reviewed-by: Thiago Macieira --- src/corelib/tools/qlocale.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 5b53b8b338..2ce410062a 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -594,7 +594,6 @@ static QLocalePrivate *c_private() */ QSystemLocale::QSystemLocale() { - delete _systemLocale; _systemLocale = this; if (system_data) -- cgit v1.2.3 From c4f122927a85dac85ba3432cf84b0d2e66c54cda Mon Sep 17 00:00:00 2001 From: Aaron Linville Date: Sat, 11 Feb 2017 23:57:44 -0500 Subject: Doc: Fix minor typos in QRectF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a couple incorrect references to the integer precision classes. Update snippet to use floating point precision classes. Task-number: QTBUG-51630 Change-Id: I9b08cfb68937a8e1179ee414d7981956ef7bc106 Reviewed-by: Martin Koller Reviewed-by: Michael Brüning Reviewed-by: Marc Mutz Reviewed-by: Topi Reiniö --- src/corelib/tools/qrect.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index 4b6183646b..895b6b9701 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -1323,8 +1323,8 @@ QDebug operator<<(QDebug dbg, const QRect &r) rendering. A QRectF can be constructed with a set of left, top, width and - height integers, or from a QPoint and a QSize. The following code - creates two identical rectangles. + height coordinates, or from a QPointF and a QSizeF. The following + code creates two identical rectangles. \snippet code/src_corelib_tools_qrect.cpp 1 @@ -1344,7 +1344,7 @@ QDebug operator<<(QDebug dbg, const QRect &r) translated copy of this rectangle. The size() function returns the rectange's dimensions as a - QSize. The dimensions can also be retrieved separately using the + QSizeF. The dimensions can also be retrieved separately using the width() and height() functions. To manipulate the dimensions use the setSize(), setWidth() or setHeight() functions. Alternatively, the size can be changed by applying either of the functions -- cgit v1.2.3