From 15881ce00a3e671126ddaaf0aeadeab584127280 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 19 Oct 2024 12:48:58 +0200 Subject: [PATCH] Utils: fix conflict of withSuffix(int) and withSuffix(qsizetype) qsizetype is equivalent to ssize_t, meaning signed 32bit on 32bit architectures, and thus this overload conflicts with withSuffix(qsizetype) version on 32bit architectures. Also, as qsizetype is a 64bit type on 64bit architectures, the fact that withSuffix(qsizetype) calls withSuffix(int) by downcasting the parameter to int means that there may be a truncation/loss in case the value is large enough. Hence, to fix both the issues: - switch the two implementations, so now withSuffix(int) calls withSuffix(qsizetype) - disable disable withSuffix(int) on 32bit architectures, as its job is already done by withSuffix(qsizetype) Change-Id: Icb82d2ba58362cc10f18cf2c41ad409c39b60863 Reviewed-by: hjk --- src/libs/utils/id.cpp | 10 +++++++--- src/libs/utils/id.h | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/id.cpp b/src/libs/utils/id.cpp index 3d894f38271..59bebb746cb 100644 --- a/src/libs/utils/id.cpp +++ b/src/libs/utils/id.cpp @@ -252,20 +252,24 @@ QStringList Id::toStringList(const QSet &ids) will be generated by appending \a suffix. */ -Id Id::withSuffix(int suffix) const +Id Id::withSuffix(qsizetype suffix) const { const QByteArray ba = name() + QByteArray::number(suffix); return Id(theId(ba.data(), ba.size())); } +#if QT_POINTER_SIZE != 4 + /*! \overload */ -Id Id::withSuffix(qsizetype suffix) const +Id Id::withSuffix(int suffix) const { - return withSuffix(int(suffix)); + return withSuffix(qsizetype(suffix)); } +#endif + /*! \overload */ diff --git a/src/libs/utils/id.h b/src/libs/utils/id.h index b40f8eecadb..0acc753bdb2 100644 --- a/src/libs/utils/id.h +++ b/src/libs/utils/id.h @@ -30,8 +30,10 @@ public: static Id generate(); - Id withSuffix(int suffix) const; Id withSuffix(qsizetype suffix) const; +#if QT_POINTER_SIZE != 4 + Id withSuffix(int suffix) const; +#endif Id withSuffix(const char suffix) const; Id withSuffix(const char *suffix) const; Id withSuffix(const QStringView suffix) const;