Fix some deprecation warnings from QCryptographicHash

QT_DEPRECATED_VERSION_X_6_4("Use the QByteArrayView overload instead")
    void addData(const char *data, qsizetype length);

Change-Id: I144765e6993a9942b372943ccbf5c783fcf9da3d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2024-05-23 16:45:28 +02:00
parent 58ac9aea68
commit 45702941f8
3 changed files with 71 additions and 71 deletions

View File

@@ -6,8 +6,6 @@
#include <QString> #include <QString>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <limits>
namespace LanguageUtils { namespace LanguageUtils {
// QTC_TEMP // QTC_TEMP
@@ -42,8 +40,8 @@ QString ComponentVersion::toString() const
void ComponentVersion::addToHash(QCryptographicHash &hash) const void ComponentVersion::addToHash(QCryptographicHash &hash) const
{ {
hash.addData(reinterpret_cast<const char *>(&_major), sizeof(_major)); hash.addData(QByteArrayView(reinterpret_cast<const char *>(&_major), sizeof(_major)));
hash.addData(reinterpret_cast<const char *>(&_minor), sizeof(_minor)); hash.addData(QByteArrayView(reinterpret_cast<const char *>(&_minor), sizeof(_minor)));
} }
} // namespace LanguageUtils } // namespace LanguageUtils

View File

@@ -6,6 +6,21 @@
using namespace LanguageUtils; using namespace LanguageUtils;
static QByteArrayView asData(const void *mem, size_t len)
{
return QByteArrayView(reinterpret_cast<const char *>(mem), len);
}
static void addData(QCryptographicHash &hash, int x)
{
hash.addData(asData(&x, sizeof(int)));
}
static void addData(QCryptographicHash &hash, const QString &x)
{
hash.addData(asData(x.constData(), x.size() * sizeof(QChar)));
}
FakeMetaEnum::FakeMetaEnum() FakeMetaEnum::FakeMetaEnum()
{} {}
@@ -39,15 +54,12 @@ bool FakeMetaEnum::hasKey(const QString &key) const
void FakeMetaEnum::addToHash(QCryptographicHash &hash) const void FakeMetaEnum::addToHash(QCryptographicHash &hash) const
{ {
int len = m_name.size(); addData(hash, m_name.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, m_name);
hash.addData(reinterpret_cast<const char *>(m_name.constData()), len * sizeof(QChar)); addData(hash, m_keys.size());
len = m_keys.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
for (const QString &key : std::as_const(m_keys)) { for (const QString &key : std::as_const(m_keys)) {
len = key.size(); addData(hash, key.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, key);
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar));
} }
} }
@@ -121,29 +133,23 @@ void FakeMetaMethod::setRevision(int r)
void FakeMetaMethod::addToHash(QCryptographicHash &hash) const void FakeMetaMethod::addToHash(QCryptographicHash &hash) const
{ {
int len = m_name.size(); addData(hash, m_name.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, m_name);
hash.addData(reinterpret_cast<const char *>(m_name.constData()), len * sizeof(QChar)); addData(hash, m_methodAccess);
hash.addData(reinterpret_cast<const char *>(&m_methodAccess), sizeof(m_methodAccess)); addData(hash, m_methodTy);
hash.addData(reinterpret_cast<const char *>(&m_methodTy), sizeof(m_methodTy)); addData(hash, m_revision);
hash.addData(reinterpret_cast<const char *>(&m_revision), sizeof(m_revision)); addData(hash, m_paramNames.size());
len = m_paramNames.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
for (const QString &pName : std::as_const(m_paramNames)) { for (const QString &pName : std::as_const(m_paramNames)) {
len = pName.size(); addData(hash, pName.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, pName);
hash.addData(reinterpret_cast<const char *>(pName.constData()), len * sizeof(QChar));
} }
len = m_paramTypes.size(); addData(hash, m_paramTypes.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
for (const QString &pType : std::as_const(m_paramTypes)) { for (const QString &pType : std::as_const(m_paramTypes)) {
len = pType.size(); addData(hash, pType.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, pType);
hash.addData(reinterpret_cast<const char *>(pType.constData()), len * sizeof(QChar));
} }
len = m_returnType.size(); addData(hash, m_returnType.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, m_returnType);
hash.addData(reinterpret_cast<const char *>(m_returnType.constData()), len * sizeof(QChar));
} }
QString FakeMetaMethod::describe(int baseIndent) const QString FakeMetaMethod::describe(int baseIndent) const
@@ -213,17 +219,15 @@ int FakeMetaProperty::revision() const
void FakeMetaProperty::addToHash(QCryptographicHash &hash) const void FakeMetaProperty::addToHash(QCryptographicHash &hash) const
{ {
int len = m_propertyName.size(); addData(hash, m_propertyName.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, m_propertyName);
hash.addData(reinterpret_cast<const char *>(m_propertyName.constData()), len * sizeof(QChar)); addData(hash, m_revision);
hash.addData(reinterpret_cast<const char *>(&m_revision), sizeof(m_revision));
int flags = (m_isList ? (1 << 0) : 0) int flags = (m_isList ? (1 << 0) : 0)
+ (m_isPointer ? (1 << 1) : 0) + (m_isPointer ? (1 << 1) : 0)
+ (m_isWritable ? (1 << 2) : 0); + (m_isWritable ? (1 << 2) : 0);
hash.addData(reinterpret_cast<const char *>(&flags), sizeof(flags)); addData(hash, flags);
len = m_type.size(); addData(hash, m_type.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, m_type);
hash.addData(reinterpret_cast<const char *>(m_type.constData()), len * sizeof(QChar));
} }
QString FakeMetaProperty::describe(int baseIndent) const QString FakeMetaProperty::describe(int baseIndent) const
@@ -361,34 +365,34 @@ QByteArray FakeMetaObject::calculateFingerprint() const
{ {
QCryptographicHash hash(QCryptographicHash::Sha1); QCryptographicHash hash(QCryptographicHash::Sha1);
int len = m_className.size(); int len = m_className.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
hash.addData(reinterpret_cast<const char *>(m_className.constData()), len * sizeof(QChar)); addData(hash, m_className);
len = m_attachedTypeName.size(); len = m_attachedTypeName.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
hash.addData(reinterpret_cast<const char *>(m_attachedTypeName.constData()), len * sizeof(QChar)); addData(hash, m_attachedTypeName);
len = m_defaultPropertyName.size(); len = m_defaultPropertyName.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
hash.addData(reinterpret_cast<const char *>(m_defaultPropertyName.constData()), len * sizeof(QChar)); addData(hash, m_defaultPropertyName);
len = m_enumNameToIndex.size(); len = m_enumNameToIndex.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
{ {
QStringList keys(m_enumNameToIndex.keys()); QStringList keys(m_enumNameToIndex.keys());
keys.sort(); keys.sort();
for (const QString &key : std::as_const(keys)) { for (const QString &key : std::as_const(keys)) {
len = key.size(); len = key.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar)); addData(hash, key);
int value = m_enumNameToIndex.value(key); int value = m_enumNameToIndex.value(key);
hash.addData(reinterpret_cast<const char *>(&value), sizeof(value)); // avoid? this adds order dependency to fingerprint... addData(hash, value);
m_enums.at(value).addToHash(hash); m_enums.at(value).addToHash(hash);
} }
} }
len = m_exports.size(); len = m_exports.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
for (const Export &e : std::as_const(m_exports)) for (const Export &e : std::as_const(m_exports))
e.addToHash(hash); // normalize order? e.addToHash(hash); // normalize order?
len = m_exports.size(); len = m_exports.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
for (const FakeMetaMethod &m : std::as_const(m_methods)) for (const FakeMetaMethod &m : std::as_const(m_methods))
m.addToHash(hash); // normalize order? m.addToHash(hash); // normalize order?
{ {
@@ -396,16 +400,16 @@ QByteArray FakeMetaObject::calculateFingerprint() const
keys.sort(); keys.sort();
for (const QString &key : std::as_const(keys)) { for (const QString &key : std::as_const(keys)) {
len = key.size(); len = key.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar)); addData(hash, key);
int value = m_propNameToIdx.value(key); int value = m_propNameToIdx.value(key);
hash.addData(reinterpret_cast<const char *>(&value), sizeof(value)); // avoid? this adds order dependency to fingerprint... addData(hash, value);
m_props.at(value).addToHash(hash); m_props.at(value).addToHash(hash);
} }
} }
len = m_superName.size(); len = m_superName.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, len);
hash.addData(reinterpret_cast<const char *>(m_superName.constData()), len * sizeof(QChar)); addData(hash, m_superName);
QByteArray res = hash.result(); QByteArray res = hash.result();
res.append('F'); res.append('F');
@@ -540,14 +544,12 @@ bool FakeMetaObject::Export::isValid() const
void FakeMetaObject::Export::addToHash(QCryptographicHash &hash) const void FakeMetaObject::Export::addToHash(QCryptographicHash &hash) const
{ {
int len = package.size(); addData(hash, package.size());
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(hash, package);
hash.addData(reinterpret_cast<const char *>(package.constData()), len * sizeof(QChar)); addData(hash, type.size());
len = type.size(); addData(hash, type);
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(type.constData()), len * sizeof(QChar));
version.addToHash(hash); version.addToHash(hash);
hash.addData(reinterpret_cast<const char *>(&metaObjectRevision), sizeof(metaObjectRevision)); addData(hash, metaObjectRevision);
} }
QString FakeMetaObject::Export::describe(int baseIndent) const QString FakeMetaObject::Export::describe(int baseIndent) const

View File

@@ -185,14 +185,14 @@ ImportKey::ImportKey(ImportType::Enum type, const QString &path, int majorVersio
void ImportKey::addToHash(QCryptographicHash &hash) const void ImportKey::addToHash(QCryptographicHash &hash) const
{ {
hash.addData(reinterpret_cast<const char *>(&type), sizeof(type)); hash.addData(QByteArrayView(reinterpret_cast<const char *>(&type), sizeof(type)));
hash.addData(reinterpret_cast<const char *>(&majorVersion), sizeof(majorVersion)); hash.addData(QByteArrayView(reinterpret_cast<const char *>(&majorVersion), sizeof(majorVersion)));
hash.addData(reinterpret_cast<const char *>(&minorVersion), sizeof(minorVersion)); hash.addData(QByteArrayView(reinterpret_cast<const char *>(&minorVersion), sizeof(minorVersion)));
for (const QString &s : splitPath) { for (const QString &s : splitPath) {
hash.addData("/", 1); hash.addData("/");
hash.addData(reinterpret_cast<const char *>(s.constData()), sizeof(QChar) * s.size()); hash.addData(QByteArrayView(reinterpret_cast<const char *>(s.constData()), sizeof(QChar) * s.size()));
} }
hash.addData("/", 1); hash.addData("/");
} }
ImportKey ImportKey::flatKey() const { ImportKey ImportKey::flatKey() const {
@@ -547,11 +547,11 @@ QByteArray DependencyInfo::calculateFingerprint(const ImportDependencies &deps)
QStringList coreImports = Utils::toList(allCoreImports); QStringList coreImports = Utils::toList(allCoreImports);
coreImports.sort(); coreImports.sort();
for (const QString &importId : std::as_const(coreImports)) { for (const QString &importId : std::as_const(coreImports)) {
hash.addData(reinterpret_cast<const char*>(importId.constData()), importId.size() * sizeof(QChar)); hash.addData(QByteArrayView(reinterpret_cast<const char*>(importId.constData()), importId.size() * sizeof(QChar)));
QByteArray coreImportFingerprint = deps.coreImport(importId).fingerprint; QByteArray coreImportFingerprint = deps.coreImport(importId).fingerprint;
hash.addData(coreImportFingerprint); hash.addData(coreImportFingerprint);
} }
hash.addData("/", 1); hash.addData("/");
QList<ImportKey> imports = Utils::toList(allImports); QList<ImportKey> imports = Utils::toList(allImports);
std::sort(imports.begin(), imports.end()); std::sort(imports.begin(), imports.end());
for (const ImportKey &k : std::as_const(imports)) for (const ImportKey &k : std::as_const(imports))