Skip to content

Commit

Permalink
Create std::wstrings out of const wchar_t* so a copy is created every…
Browse files Browse the repository at this point in the history
… time.

Signed-off-by: allexzander <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Apr 6, 2021
1 parent 454226b commit 0a33e99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/libsync/vfs/cfapi/cfapiwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ bool deleteSyncRootRegistryKey(const QString &syncRootPath, const QString &provi
return true;
}

OCC::Result<void, QString> OCC::CfApiWrapper::registerSyncRoot(const QString path, const QString providerName, const QString providerVersion, const QString folderAlias, const QString displayName, const QString accountDisplayName)
OCC::Result<void, QString> OCC::CfApiWrapper::registerSyncRoot(const QString &path, const QString &providerName, const QString &providerVersion, const QString &folderAlias, const QString &displayName, const QString &accountDisplayName)
{
// even if we fail to register our sync root with shell, we can still proceed with using the VFS
const auto createRegistryKeyResult = createSyncRootRegistryKeys(providerName, folderAlias, displayName, accountDisplayName, path);
Expand All @@ -460,9 +460,11 @@ OCC::Result<void, QString> OCC::CfApiWrapper::registerSyncRoot(const QString pat
qCWarning(lcCfApiWrapper) << "Failed to create the registry key for path:" << path;
}

const auto p = path.toStdWString();
const auto name = providerName.toStdWString();
const auto version = providerVersion.toStdWString();
// API is somehow keeping the pointers for longer than one would expect or freeing them itself
// the internal format of QString is likely the right one for wstring on Windows so there's in fact not necessarily a need to copy
const auto p = std::wstring(path.toStdWString().data());
const auto name = std::wstring(providerName.toStdWString().data());
const auto version = std::wstring(providerVersion.toStdWString().data());

CF_SYNC_REGISTRATION info;
info.ProviderName = name.data();
Expand All @@ -489,7 +491,7 @@ OCC::Result<void, QString> OCC::CfApiWrapper::registerSyncRoot(const QString pat
}
}

OCC::Result<void, QString> OCC::CfApiWrapper::unregisterSyncRoot(const QString path, const QString providerName, const QString accountDisplayName)
OCC::Result<void, QString> OCC::CfApiWrapper::unregisterSyncRoot(const QString &path, const QString &providerName, const QString &accountDisplayName)
{
const auto deleteRegistryKeyResult = deleteSyncRootRegistryKey(path, providerName, accountDisplayName);
Q_ASSERT(deleteRegistryKeyResult);
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/vfs/cfapi/cfapiwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class OWNCLOUDSYNC_EXPORT PlaceHolderInfo
std::unique_ptr<CF_PLACEHOLDER_BASIC_INFO, Deleter> _data;
};

OWNCLOUDSYNC_EXPORT Result<void, QString> registerSyncRoot(const QString path, const QString providerName, const QString providerVersion, const QString folderAlias, const QString displayName, const QString accountDisplayName);
OWNCLOUDSYNC_EXPORT Result<void, QString> unregisterSyncRoot(const QString path, const QString providerName, const QString accountDisplayName);
OWNCLOUDSYNC_EXPORT Result<void, QString> registerSyncRoot(const QString &path, const QString &providerName, const QString &providerVersion, const QString &folderAlias, const QString &displayName, const QString &accountDisplayName);
OWNCLOUDSYNC_EXPORT Result<void, QString> unregisterSyncRoot(const QString &path, const QString &providerName, const QString &accountDisplayName);

OWNCLOUDSYNC_EXPORT Result<ConnectionKey, QString> connectSyncRoot(const QString &path, VfsCfApi *context);
OWNCLOUDSYNC_EXPORT Result<void, QString> disconnectSyncRoot(ConnectionKey &&key);
Expand Down

0 comments on commit 0a33e99

Please sign in to comment.