diff options
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 12 | ||||
-rw-r--r-- | src/corelib/global/qglobal.h | 14 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index b17125d4ab..8d80a32ad5 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2901,18 +2901,18 @@ enum { QByteArray QSysInfo::machineUniqueId() { #ifdef Q_OS_BSD4 - char uuid[UuidStringLen]; + char uuid[UuidStringLen + 1]; size_t uuidlen = sizeof(uuid); # ifdef KERN_HOSTUUID int name[] = { CTL_KERN, KERN_HOSTUUID }; if (sysctl(name, sizeof name / sizeof name[0], &uuid, &uuidlen, nullptr, 0) == 0 && uuidlen == sizeof(uuid)) - return QByteArray(uuid, uuidlen); + return QByteArray(uuid, uuidlen - 1); # else // Darwin: no fixed value, we need to search by name if (sysctlbyname("kern.uuid", uuid, &uuidlen, nullptr, 0) == 0 && uuidlen == sizeof(uuid)) - return QByteArray(uuid, uuidlen); + return QByteArray(uuid, uuidlen - 1); # endif #elif defined(Q_OS_UNIX) // The modern name on Linux is /etc/machine-id, but that path is @@ -2935,7 +2935,7 @@ QByteArray QSysInfo::machineUniqueId() #elif defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // Let's poke at the registry HKEY key = NULL; - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ, &key) + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ | KEY_WOW64_64KEY, &key) == ERROR_SUCCESS) { wchar_t buffer[UuidStringLen + 1]; DWORD size = sizeof(buffer); @@ -2976,11 +2976,11 @@ QByteArray QSysInfo::bootUniqueId() } #elif defined(Q_OS_DARWIN) // "kern.bootsessionuuid" is only available by name - char uuid[UuidStringLen]; + char uuid[UuidStringLen + 1]; size_t uuidlen = sizeof(uuid); if (sysctlbyname("kern.bootsessionuuid", uuid, &uuidlen, nullptr, 0) == 0 && uuidlen == sizeof(uuid)) - return QByteArray(uuid, uuidlen); + return QByteArray(uuid, uuidlen - 1); #endif return QByteArray(); }; diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index b608489576..ccab228804 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1037,14 +1037,20 @@ for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \ template <typename T> inline T *qGetPtrHelper(T *ptr) { return ptr; } template <typename Ptr> inline auto qGetPtrHelper(const Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); } +// The body must be a statement: +#define Q_CAST_IGNORE_ALIGN(body) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wcast-align") body QT_WARNING_POP #define Q_DECLARE_PRIVATE(Class) \ - inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \ - inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \ + inline Class##Private* d_func() \ + { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr));) } \ + inline const Class##Private* d_func() const \ + { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr));) } \ friend class Class##Private; #define Q_DECLARE_PRIVATE_D(Dptr, Class) \ - inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr)); } \ - inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr)); } \ + inline Class##Private* d_func() \ + { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr));) } \ + inline const Class##Private* d_func() const \ + { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr));) } \ friend class Class##Private; #define Q_DECLARE_PUBLIC(Class) \ |