From 1d466499f6abc58e0c815da8a25d87047e1e9c7f Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 14 Sep 2021 11:54:13 +0200 Subject: [PATCH] Fix bug in mime type magic rules with Qt 6.2 There was a bug in the copying and comparison of mime magic rules, that did not copy/compare the sub-rules. With Qt 5 this was probably never actually used, because we save the magic rules in a QList, and that didn't use MimeMagicRule as "values", but internally used pointers to heap-allocated objects, so e.g. appending a list of rules to another list of rules would only copy the pointers to the actual objects (as long as the items were never modified). In Qt 6, QList has the same semantics as QVector, so MimeMagicRule is actually used as values, which uses the copy operations. As a result, the moment the MimeMagicRule was copied from the parser to the mime type, it would loose its sub-rules. Which breaks the whole mime magic logic, and leads to wrong mime type resolution, e.g. for *.ui files. Change-Id: I90c46264423f18f73a6efc01887a0b8b6199d35d Reviewed-by: Christian Stenger --- src/libs/utils/mimetypes/mimemagicrule.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/mimetypes/mimemagicrule.cpp b/src/libs/utils/mimetypes/mimemagicrule.cpp index 0aa0a6ad485..1293e00f65a 100644 --- a/src/libs/utils/mimetypes/mimemagicrule.cpp +++ b/src/libs/utils/mimetypes/mimemagicrule.cpp @@ -359,8 +359,9 @@ MimeMagicRule::MimeMagicRule(MimeMagicRule::Type theType, } } -MimeMagicRule::MimeMagicRule(const MimeMagicRule &other) : - d(new MimeMagicRulePrivate(*other.d)) +MimeMagicRule::MimeMagicRule(const MimeMagicRule &other) + : m_subMatches(other.m_subMatches) + , d(new MimeMagicRulePrivate(*other.d)) { } @@ -369,13 +370,13 @@ MimeMagicRule::~MimeMagicRule() = default; MimeMagicRule &MimeMagicRule::operator=(const MimeMagicRule &other) { *d = *other.d; + m_subMatches = other.m_subMatches; return *this; } bool MimeMagicRule::operator==(const MimeMagicRule &other) const { - return d == other.d || - *d == *other.d; + return (d == other.d || *d == *other.d) && m_subMatches == other.m_subMatches; } MimeMagicRule::Type MimeMagicRule::type() const