From b9f96cacc99c8a242f45f4581843a6b1c67501f4 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 27 May 2019 19:00:09 +0200 Subject: QRegExp: remove an out of bounds access into QString ... spotted with the brand-new checks for that in QCharRef. The rx[i] == ~~~ check is clearly wrong, as rx is the regexp we're building and `i` was not supposed to index into it. The intended meaning was wc[i] == ~~~, testing if we were seeing the closing bracket of a character set. We need to check for that immediately for dealing with the special syntax of []...] where the ] belongs to the character set (it can't be the closing one as character sets cannot be empty). Fix and add a regression test. Bonus: this code was almost unchanged since 2009. Change-Id: I958cd87fc25558e9d202d18b3dd4a35d0db16d8d Reviewed-by: Marc Mutz Reviewed-by: hjk --- src/corelib/tools/qregexp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 87b30c952e..ef24c952eb 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -825,7 +825,7 @@ static QString wc2rx(const QString &wc_str, const bool enableEscaping) if (wc[i] == QLatin1Char('^')) rx += wc[i++]; if (i < wclen) { - if (rx[i] == QLatin1Char(']')) + if (wc[i] == QLatin1Char(']')) rx += wc[i++]; while (i < wclen && wc[i] != QLatin1Char(']')) { if (wc[i] == QLatin1Char('\\')) -- cgit v1.2.3 From 978987981ac1ad0689e042cc241c1732496b59bb Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 22 May 2019 14:56:58 +0200 Subject: Automatically sysrootify $$[FOO/get] properties If automatic sysrootification is in effect (SysrootifyPrefix=true in qt.conf) then the qmake property variants $$[FOO] and $$[FOO/get] must be sysrootified. The latter was never sysrootified. All other variants (src, dev, raw) are supposed to be without sysroot. Flesh out a sysrootify function and readabilitify the code a bit while we're at it. Fixes: QTBUG-71673 Change-Id: Ifcbce8c035b9da447da9d6937edd5a4aa84573ba Reviewed-by: Oliver Wolff --- src/corelib/global/qlibraryinfo.cpp | 35 ++++++++++++++++++++++------------- src/corelib/global/qlibraryinfo.h | 1 + 2 files changed, 23 insertions(+), 13 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 4119012d85..d19e54154e 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -432,7 +432,24 @@ void QLibraryInfo::reload() { QLibraryInfoPrivate::reload(); } -#endif + +void QLibraryInfo::sysrootify(QString *path) +{ + if (!QVariant::fromValue(rawLocation(SysrootifyPrefixPath, FinalPaths)).toBool()) + return; + + const QString sysroot = rawLocation(SysrootPath, FinalPaths); + if (sysroot.isEmpty()) + return; + + if (path->length() > 2 && path->at(1) == QLatin1Char(':') + && (path->at(2) == QLatin1Char('/') || path->at(2) == QLatin1Char('\\'))) { + path->replace(0, 2, sysroot); // Strip out the drive on Windows targets + } else { + path->prepend(sysroot); + } +} +#endif // QT_BUILD_QMAKE /*! Returns the location specified by \a loc. @@ -444,18 +461,8 @@ QLibraryInfo::location(LibraryLocation loc) QString ret = rawLocation(loc, FinalPaths); // Automatically prepend the sysroot to target paths - if (loc < SysrootPath || loc > LastHostPath) { - QString sysroot = rawLocation(SysrootPath, FinalPaths); - if (!sysroot.isEmpty() - && QVariant::fromValue(rawLocation(SysrootifyPrefixPath, FinalPaths)).toBool()) { - if (ret.length() > 2 && ret.at(1) == QLatin1Char(':') - && (ret.at(2) == QLatin1Char('/') || ret.at(2) == QLatin1Char('\\'))) { - ret.replace(0, 2, sysroot); // Strip out the drive on Windows targets - } else { - ret.prepend(sysroot); - } - } - } + if (loc < SysrootPath || loc > LastHostPath) + sysrootify(&ret); return ret; } @@ -598,6 +605,8 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group) } else { // we make any other path absolute to the prefix directory baseDir = rawLocation(PrefixPath, group); + if (group == EffectivePaths) + sysrootify(&baseDir); } #else if (loc == PrefixPath) { diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h index 80fc5bd4fc..9414af9b7d 100644 --- a/src/corelib/global/qlibraryinfo.h +++ b/src/corelib/global/qlibraryinfo.h @@ -107,6 +107,7 @@ public: enum PathGroup { FinalPaths, EffectivePaths, EffectiveSourcePaths, DevicePaths }; static QString rawLocation(LibraryLocation, PathGroup); static void reload(); + static void sysrootify(QString *path); #endif static QStringList platformPluginArguments(const QString &platformName); -- cgit v1.2.3 From a67b25067ee78e0c2bc4e77a4c61af43528d9bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 27 May 2019 18:36:13 +0200 Subject: Rename QMacScopedObserver to the more fittingly QMacNotificationObserver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1d8280fe88871572a3a27e612de49717b3b9ef77 Reviewed-by: Tor Arne Vestbø --- src/corelib/kernel/qcore_mac_p.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index f96e7358a2..2428faed15 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -295,13 +295,13 @@ QT_MAC_WEAK_IMPORT(_os_activity_current); // ------------------------------------------------------------------------- #if defined( __OBJC__) -class QMacScopedObserver +class QMacNotificationObserver { public: - QMacScopedObserver() {} + QMacNotificationObserver() {} template - QMacScopedObserver(id object, NSNotificationName name, Functor callback) { + QMacNotificationObserver(id object, NSNotificationName name, Functor callback) { observer = [[NSNotificationCenter defaultCenter] addObserverForName:name object:object queue:nil usingBlock:^(NSNotification *) { callback(); @@ -309,13 +309,13 @@ public: ]; } - QMacScopedObserver(const QMacScopedObserver& other) = delete; - QMacScopedObserver(QMacScopedObserver&& other) : observer(other.observer) { + QMacNotificationObserver(const QMacNotificationObserver& other) = delete; + QMacNotificationObserver(QMacNotificationObserver&& other) : observer(other.observer) { other.observer = nil; } - QMacScopedObserver &operator=(const QMacScopedObserver& other) = delete; - QMacScopedObserver &operator=(QMacScopedObserver&& other) { + QMacNotificationObserver &operator=(const QMacNotificationObserver& other) = delete; + QMacNotificationObserver &operator=(QMacNotificationObserver&& other) { if (this != &other) { remove(); observer = other.observer; @@ -329,7 +329,7 @@ public: [[NSNotificationCenter defaultCenter] removeObserver:observer]; observer = nil; } - ~QMacScopedObserver() { remove(); } + ~QMacNotificationObserver() { remove(); } private: id observer = nil; -- cgit v1.2.3 From 7029ecade96876d08af7d576e0b81417502acbaa Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Mon, 20 May 2019 11:37:27 +0200 Subject: cmake: correct version dependency for qt5_add_big_resources qt5_add_big_resources is only available if using CMake 3.9 and later. This amends cdccd0222bbed1954d5d7fe0da9d2308c202f3b1. Task-number: QTBUG-55680 Task-number: QTBUG-75806 Change-Id: Ibba7af6ee7edfb226368937d543b7ec5cc93eb16 Reviewed-by: Alexandru Croitor Reviewed-by: Kai Koehne --- src/corelib/Qt5CoreMacros.cmake | 5 +++++ src/corelib/doc/src/cmake-macros.qdoc | 2 ++ 2 files changed, 7 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/Qt5CoreMacros.cmake b/src/corelib/Qt5CoreMacros.cmake index 7ae5e4fd16..3a60b8e0d2 100644 --- a/src/corelib/Qt5CoreMacros.cmake +++ b/src/corelib/Qt5CoreMacros.cmake @@ -296,6 +296,9 @@ endfunction() # qt5_add_big_resources(outfiles inputfile ... ) function(QT5_ADD_BIG_RESOURCES outfiles ) + if (CMAKE_VERSION VERSION_LESS 3.9) + message(FATAL_ERROR, "qt5_add_big_resources requires CMake 3.9 or newer") + endif() set(options) set(oneValueArgs) @@ -326,6 +329,8 @@ function(QT5_ADD_BIG_RESOURCES outfiles ) set_target_properties(rcc_object_${outfilename} PROPERTIES AUTOMOC OFF) set_target_properties(rcc_object_${outfilename} PROPERTIES AUTOUIC OFF) add_dependencies(rcc_object_${outfilename} big_resources_${outfilename}) + # The modification of TARGET_OBJECTS needs the following change in cmake + # https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f add_custom_command(OUTPUT ${outfile} COMMAND ${Qt5Core_RCC_EXECUTABLE} ARGS ${rcc_options} --name ${outfilename} --pass 2 --temp $ --output ${outfile} ${infile} diff --git a/src/corelib/doc/src/cmake-macros.qdoc b/src/corelib/doc/src/cmake-macros.qdoc index 6140e8be44..7fb133020f 100644 --- a/src/corelib/doc/src/cmake-macros.qdoc +++ b/src/corelib/doc/src/cmake-macros.qdoc @@ -131,6 +131,8 @@ files (\c .o, \c .obj) files instead of C++ source code. This allows to embed bigger resources, where compiling to C++ sources and then to binaries would be too time consuming or memory intensive. +Note that this macro is only available if using \c{CMake} 3.9 or later. + \section1 Arguments You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls. -- cgit v1.2.3 From 8c7589d992a5615fa3a98f67d098d5a2fca579cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Wed, 29 May 2019 18:02:19 +0200 Subject: Do not strip off the fragment and query in the qfileselector This is needed for cases where we use e.g. "file:///test.html?query#Fragment". The fragment and query were already preserved for the qrc scheme. This fixes it for the file scheme. Change-Id: I5713e4a25372fdd55ac255b1c6228b4dea419244 Reviewed-by: Shawn Rutledge --- src/corelib/io/qfileselector.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp index ce06c8e00b..500b475d1d 100644 --- a/src/corelib/io/qfileselector.cpp +++ b/src/corelib/io/qfileselector.cpp @@ -228,7 +228,18 @@ QUrl QFileSelector::select(const QUrl &filePath) const QString selectedPath = d->select(equivalentPath); ret.setPath(selectedPath.remove(0, scheme.size())); } else { + // we need to store the original query and fragment, since toLocalFile() will strip it off + QString frag; + if (ret.hasFragment()) + frag = ret.fragment(); + QString query; + if (ret.hasQuery()) + query= ret.query(); ret = QUrl::fromLocalFile(d->select(ret.toLocalFile())); + if (!frag.isNull()) + ret.setFragment(frag); + if (!query.isNull()) + ret.setQuery(query); } return ret; } -- cgit v1.2.3 From ff4ef79e0ddc1310262d2db60e6f9ba51df9dc6c Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 24 May 2019 14:20:43 +0200 Subject: Overhaul Q(Date|Time)+ documentation Various things were out of date, misdescribed or just plain wrong. Change-Id: I11b7bd419604067fce2577a42882ebf126629016 Reviewed-by: Paul Wicking --- src/corelib/tools/qdatetime.cpp | 199 +++++++++++++++++++++------------------- 1 file changed, 103 insertions(+), 96 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 3cba786865..b0e443c3dc 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -326,19 +326,17 @@ static int fromOffsetString(const QStringRef &offsetString, bool *valid) Q_DECL_ \brief The QDate class provides date functions. - A QDate object encodes a calendar date, i.e. year, month, and day numbers, - in the proleptic Gregorian calendar by default. It can read the current date - from the system clock. It provides functions for comparing dates, and for - manipulating dates. For example, it is possible to add and subtract days, - months, and years to dates. + A QDate object represents a particular date. This can be expressed as a + calendar date, i.e. year, month, and day numbers, in the proleptic Gregorian + calendar. A QDate object is typically created by giving the year, month, and day - numbers explicitly. Note that QDate interprets two digit years as presented, - i.e., as years 0 through 99, without adding any offset. A QDate can also be - constructed with the static function currentDate(), which creates a QDate - object containing the system clock's date. An explicit date can also be set - using setDate(). The fromString() function returns a QDate given a string - and a date format which is used to interpret the date within the string. + numbers explicitly. Note that QDate interprets year numbers less than 100 as + presented, i.e., as years 1 through 99, without adding any offset. The + static function currentDate() creates a QDate object containing the date + read from the system clock. An explicit date can also be set using + setDate(). The fromString() function returns a QDate given a string and a + date format which is used to interpret the date within the string. The year(), month(), and day() functions provide access to the year, month, and day numbers. Also, dayOfWeek() and dayOfYear() @@ -372,7 +370,7 @@ static int fromOffsetString(const QStringRef &offsetString, bool *valid) Q_DECL_ every day in a contiguous range, with 24 November 4714 BCE in the Gregorian calendar being Julian Day 0 (1 January 4713 BCE in the Julian calendar). As well as being an efficient and accurate way of storing an absolute date, - it is suitable for converting a Date into other calendar systems such as + it is suitable for converting a date into other calendar systems such as Hebrew, Islamic or Chinese. The Julian Day number can be obtained using QDate::toJulianDay() and can be set using QDate::fromJulianDay(). @@ -1434,12 +1432,10 @@ bool QDate::isLeapYear(int y) Unlike QDateTime, QTime knows nothing about time zones or daylight-saving time (DST). - A QTime object is typically created either by giving the number - of hours, minutes, seconds, and milliseconds explicitly, or by - using the static function currentTime(), which creates a QTime - object that contains the system's local time. Note that the - accuracy depends on the accuracy of the underlying operating - system; not all systems provide 1-millisecond accuracy. + A QTime object is typically created either by giving the number of hours, + minutes, seconds, and milliseconds explicitly, or by using the static + function currentTime(), which creates a QTime object that represents the + system's local time. The hour(), minute(), second(), and msec() functions provide access to the number of hours, minutes, seconds, and milliseconds @@ -1899,6 +1895,12 @@ int QTime::msecsTo(const QTime &t) const Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy. + + Furthermore, currentTime() only increases within each day; it shall drop by + 24 hours each time midnight passes; and, beside this, changes in it may not + correspond to elapsed time, if a daylight-saving transition intervenes. + + \sa QDateTime::currentDateTime(), QDateTime::curentDateTimeUtc() */ #if QT_CONFIG(datestring) @@ -3027,15 +3029,30 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT provides functions for comparing datetimes and for manipulating a datetime by adding a number of seconds, days, months, or years. - A QDateTime object is typically created either by giving a date - and time explicitly in the constructor, or by using the static - function currentDateTime() that returns a QDateTime object set - to the system clock's time. The date and time can be changed with - setDate() and setTime(). A datetime can also be set using the - setTime_t() function that takes a POSIX-standard "number of - seconds since 00:00:00 on January 1, 1970" value. The fromString() - function returns a QDateTime, given a string and a date format - used to interpret the date within the string. + QDateTime can describe datetimes with respect to \l{Qt::LocalTime}{local + time}, to \l{Qt::UTC}{UTC}, to a specified \l{{Qt::OffsetFromUTC}{offset + from UTC} or to a specified \l{{Qt::TimeZone}{time zone}, in conjunction + with the QTimeZone class. For example, a time zone of "Europe/Berlin" will + apply the daylight-saving rules as used in Germany since 1970. In contrast, + an offset from UTC of +3600 seconds is one hour ahead of UTC (usually + written in ISO standard notation as "UTC+01:00"), with no daylight-saving + offset or changes. When using either local time or a specified time zone, + time-zone transitions such as the starts and ends of daylight-saving time + (DST) are taken into account. The choice of system used to represent a + datetime is described as its "timespec". + + A QDateTime object is typically created either by giving a date and time + explicitly in the constructor, or by using a static function such as + currentDateTime() or fromMSecsSinceEpoch(). The date and time can be changed + with setDate() and setTime(). A datetime can also be set using the + setMSecsSinceEpoch() function that takes the time, in milliseconds, since + 00:00:00 on January 1, 1970. The fromString() function returns a QDateTime, + given a string and a date format used to interpret the date within the + string. + + QDateTime::currentDateTime() returns a QDateTime that expresses the current + time with respect to local time. QDateTime::currentDateTimeUtc() returns a + QDateTime that expresses the current time with respect to UTC. The date() and time() functions provide access to the date and time parts of the datetime. The same information is provided in @@ -3046,18 +3063,20 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT later. You can increment (or decrement) a datetime by a given number of - milliseconds using addMSecs(), seconds using addSecs(), or days - using addDays(). Similarly, you can use addMonths() and addYears(). - The daysTo() function returns the number of days between two datetimes, - secsTo() returns the number of seconds between two datetimes, and - msecsTo() returns the number of milliseconds between two datetimes. - - QDateTime can store datetimes as \l{Qt::LocalTime}{local time} or - as \l{Qt::UTC}{UTC}. QDateTime::currentDateTime() returns a - QDateTime expressed as local time; use toUTC() to convert it to - UTC. You can also use timeSpec() to find out if a QDateTime - object stores a UTC time or a local time. Operations such as - addSecs() and secsTo() are aware of daylight-saving time (DST). + milliseconds using addMSecs(), seconds using addSecs(), or days using + addDays(). Similarly, you can use addMonths() and addYears(). The daysTo() + function returns the number of days between two datetimes, secsTo() returns + the number of seconds between two datetimes, and msecsTo() returns the + number of milliseconds between two datetimes. These operations are aware of + daylight-saving time (DST) and other time-zone transitions, where + applicable. + + Use toTimeSpec() to express a datetime in local time or UTC, + toOffsetFromUtc() to express in terms of an offset from UTC, or toTimeZone() + to express it with respect to a general time zone. You can use timeSpec() to + find out what time-spec a QDateTime object stores its time relative to. When + that is Qt::TimeZone, you can use timeZone() to find out which zone it is + using. \note QDateTime does not account for leap seconds. @@ -3071,67 +3090,55 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT \section2 Range of Valid Dates - The range of valid values able to be stored in QDateTime is dependent on - the internal storage implementation. QDateTime is currently stored in a - qint64 as a serial msecs value encoding the date and time. This restricts - the date range to about +/- 292 million years, compared to the QDate range - of +/- 2 billion years. Care must be taken when creating a QDateTime with - extreme values that you do not overflow the storage. The exact range of - supported values varies depending on the Qt::TimeSpec and time zone. + The range of values that QDateTime can represent is dependent on the + internal storage implementation. QDateTime is currently stored in a qint64 + as a serial msecs value encoding the date and time. This restricts the date + range to about +/- 292 million years, compared to the QDate range of +/- 2 + billion years. Care must be taken when creating a QDateTime with extreme + values that you do not overflow the storage. The exact range of supported + values varies depending on the Qt::TimeSpec and time zone. + + \section2 Use of Timezones + + QDateTime uses the system's time zone information to determine the current + local time zone and its offset from UTC. If the system is not configured + correctly or not up-to-date, QDateTime will give wrong results. - \section2 Use of System Timezone + QDateTime likewise uses system-provided information to determine the offsets + of other timezones from UTC. If this information is incomplete or out of + date, QDateTime will give wrong results. See the QTimeZone documentation for + more details. - QDateTime uses the system's time zone information to determine the - offset of local time from UTC. If the system is not configured - correctly or not up-to-date, QDateTime will give wrong results as - well. + On modern Unix systems, this means QDateTime usually has accurate + information about historical transitions (including DST, see below) whenever + possible. On Windows, where the system doesn't support historical timezone + data, historical accuracy is not maintained with respect to timezone + transitions, notably including DST. \section2 Daylight-Saving Time (DST) - QDateTime takes into account the system's time zone information - when dealing with DST. On modern Unix systems, this means it - applies the correct historical DST data whenever possible. On - Windows, where the system doesn't support historical DST data, - historical accuracy is not maintained with respect to DST. - - The range of valid dates taking DST into account is 1970-01-01 to - the present, and rules are in place for handling DST correctly - until 2037-12-31, but these could change. For dates falling - outside that range, QDateTime makes a \e{best guess} using the - rules for year 1970 or 2037, but we can't guarantee accuracy. This - means QDateTime doesn't take into account changes in a locale's - time zone before 1970, even if the system's time zone database - supports that information. - - QDateTime takes into consideration the Standard Time to Daylight-Saving Time - transition. For example if the transition is at 2am and the clock goes - forward to 3am, then there is a "missing" hour from 02:00:00 to 02:59:59.999 - which QDateTime considers to be invalid. Any date maths performed - will take this missing hour into account and return a valid result. - - \section2 Offset From UTC - - A Qt::TimeSpec of Qt::OffsetFromUTC is also supported. This allows you - to define a QDateTime relative to UTC at a fixed offset of a given number - of seconds from UTC. For example, an offset of +3600 seconds is one hour - ahead of UTC and is usually written in ISO standard notation as - "UTC+01:00". Daylight-Saving Time never applies with this TimeSpec. - - There is no explicit size restriction to the offset seconds, but there is - an implicit limit imposed when using the toString() and fromString() - methods which use a format of [+|-]hh:mm, effectively limiting the range - to +/- 99 hours and 59 minutes and whole minutes only. Note that currently - no time zone lies outside the range of +/- 14 hours. - - \section2 Time Zone Support - - A Qt::TimeSpec of Qt::TimeZone is also supported in conjunction with the - QTimeZone class. This allows you to define a datetime in a named time zone - adhering to a consistent set of daylight-saving transition rules. For - example a time zone of "Europe/Berlin" will apply the daylight-saving - rules as used in Germany since 1970. Note that the transition rules - applied depend on the platform support. See the QTimeZone documentation - for more details. + QDateTime takes into account transitions between Standard Time and + Daylight-Saving Time. For example, if the transition is at 2am and the clock + goes forward to 3am, then there is a "missing" hour from 02:00:00 to + 02:59:59.999 which QDateTime considers to be invalid. Any date arithmetic + performed will take this missing hour into account and return a valid + result. For example, adding one minute to 01:59:59 will get 03:00:00. + + The range of valid dates taking DST into account is 1970-01-01 to the + present, and rules are in place for handling DST correctly until 2037-12-31, + but these could change. For dates falling outside that range, QDateTime + makes a \e{best guess} using the rules for year 1970 or 2037, but we can't + guarantee accuracy. This means QDateTime doesn't take into account changes + in a time zone before 1970, even if the system's time zone database provides + that information. + + \section2 Offsets From UTC + + There is no explicit size restriction on an offset from UTC, but there is an + implicit limit imposed when using the toString() and fromString() methods + which use a [+|-]hh:mm format, effectively limiting the range to +/- 99 + hours and 59 minutes and whole minutes only. Note that currently no time + zone lies outside the range of +/- 14 hours. \sa QDate, QTime, QDateTimeEdit, QTimeZone */ @@ -4254,7 +4261,7 @@ qint64 QDateTime::msecsTo(const QDateTime &other) const Example: \snippet code/src_corelib_tools_qdatetime.cpp 16 - \sa timeSpec(), toTimeZone(), toUTC(), toLocalTime() + \sa timeSpec(), toTimeZone(), toOffsetFromUtc() */ QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const -- cgit v1.2.3 From 4ebac33644d5db0b727680f1dacb18616daafe86 Mon Sep 17 00:00:00 2001 From: Damien Caliste Date: Mon, 20 May 2019 15:44:18 +0200 Subject: Detect system time zone from linked symlinks [ChangeLog][QtCore][QTimeZone] The IANA timezone database backend now properly follows symlinks even when they point to variable locations like /run or /var (useful when /etc is mounted read-only). Fixes: QTBUG-75936 Fixes: QTBUG-75527 Change-Id: If0dc2bfa20659e76c3bd062c75597a9ad01ad954 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/tools/qtimezoneprivate_tz.cpp | 43 +++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index 7d85bc077d..57bc000af5 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -51,6 +51,12 @@ #include "qlocale_tools_p.h" #include +#include +#include +#if !defined(Q_OS_INTEGRITY) +#include // to use MAXSYMLINKS constant +#endif +#include // to use _SC_SYMLOOP_MAX constant QT_BEGIN_NAMESPACE @@ -1045,6 +1051,27 @@ QTimeZonePrivate::Data QTzTimeZonePrivate::previousTransition(qint64 beforeMSecs return last > m_tranTimes.cbegin() ? dataForTzTransition(*--last) : invalidData(); } +static long getSymloopMax() +{ +#if defined(SYMLOOP_MAX) + return SYMLOOP_MAX; // if defined, at runtime it can only be greater than this, so this is a safe bet +#else + errno = 0; + long result = sysconf(_SC_SYMLOOP_MAX); + if (result >= 0) + return result; + // result is -1, meaning either error or no limit + Q_ASSERT(!errno); // ... but it can't be an error, POSIX mandates _SC_SYMLOOP_MAX + + // therefore we can make up our own limit +# if defined(MAXSYMLINKS) + return MAXSYMLINKS; +# else + return 8; +# endif +#endif +} + // TODO Could cache the value and monitor the required files for any changes QByteArray QTzTimeZonePrivate::systemTimeZoneId() const { @@ -1062,12 +1089,18 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const // On most distros /etc/localtime is a symlink to a real file so extract name from the path if (ianaId.isEmpty()) { - const QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime")); - if (!path.isEmpty()) { + const QLatin1String zoneinfo("/zoneinfo/"); + QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime")); + int index = -1; + long iteration = getSymloopMax(); + // Symlink may point to another symlink etc. before being under zoneinfo/ + // We stop on the first path under /zoneinfo/, even if it is itself a + // symlink, like America/Montreal pointing to America/Toronto + while (iteration-- > 0 && !path.isEmpty() && (index = path.indexOf(zoneinfo)) < 0) + path = QFile::symLinkTarget(path); + if (index >= 0) { // /etc/localtime is a symlink to the current TZ file, so extract from path - int index = path.indexOf(QLatin1String("/zoneinfo/")); - if (index != -1) - ianaId = path.mid(index + 10).toUtf8(); + ianaId = path.mid(index + zoneinfo.size()).toUtf8(); } } -- cgit v1.2.3