Skip to content

Commit

Permalink
Fix hash comparisons
Browse files Browse the repository at this point in the history
Not sure where the bug is but it looks like with Qt 6.6.2 and gcc 14.0.1
the return type of qHash() is not the expected uint unless explicitly
stored as one.

    > g++ --version
    g++ (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0)
    ...
  • Loading branch information
hluk committed Apr 24, 2024
1 parent 51b440c commit 93b6549
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/scriptable/scriptable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3469,8 +3469,9 @@ bool Scriptable::canSynchronizeSelection(ClipboardMode targetMode)
const QString owner = sourceData.value(mimeOwner).toString();
if ( owner.isEmpty() && !source.isEmpty() ) {
const auto sourceTextHash = m_data.value(COPYQ_MIME_PREFIX "source-text-hash").toByteArray().toUInt();
if (sourceTextHash != qHash(source)) {
COPYQ_LOG(QStringLiteral("Sync: Cancelled - source text changed"));
const uint newSourceTextHash = qHash(source);
if (sourceTextHash != newSourceTextHash) {
COPYQ_LOG("Sync: Cancelled - source text changed");
return false;
}
}
Expand All @@ -3485,24 +3486,25 @@ bool Scriptable::canSynchronizeSelection(ClipboardMode targetMode)
const QString owner = targetData.value(mimeOwner).toString();
if ( owner.isEmpty() && !target.isEmpty() ) {
const auto targetTextHash = m_data.value(COPYQ_MIME_PREFIX "target-text-hash").toByteArray().toUInt();
if (targetTextHash != qHash(target)) {
COPYQ_LOG(QStringLiteral("Sync: Cancelled - target text changed"));
const uint newTargetTextHash = qHash(target);
if (targetTextHash != newTargetTextHash) {
COPYQ_LOG("Sync: Cancelled - target text changed");
return false;
}
}

// Stop if the clipboard and selection text is already synchronized
// or user selected text and copied it to clipboard.
if (!sourceData.isEmpty() && source == target) {
COPYQ_LOG(QStringLiteral("Sync: Cancelled - target text is already same as source"));
COPYQ_LOG("Sync: Cancelled - target text is already same as source");
return false;
}
} else {
COPYQ_LOG(QStringLiteral("Sync: Failed to fetch target data"));
COPYQ_LOG("Sync: Failed to fetch target data");
}

if (m_abort != Abort::None) {
COPYQ_LOG(QStringLiteral("Sync: Aborting"));
COPYQ_LOG("Sync: Aborting");
return false;
}

Expand Down

0 comments on commit 93b6549

Please sign in to comment.