mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 23:39:45 -05:00
Various minor code improvements
This commit is contained in:
parent
125a81f2ed
commit
96438a45b4
@ -166,15 +166,16 @@ if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4")
|
||||
set(IS_32BIT TRUE)
|
||||
endif()
|
||||
|
||||
set(CLANG_COMPILER_ID_REGEX "^(Apple)?[Cc]lang$")
|
||||
if("${CMAKE_C_COMPILER}" MATCHES "clang$"
|
||||
OR "${CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS}" MATCHES "__clang__"
|
||||
OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
OR "${CMAKE_C_COMPILER_ID}" MATCHES ${CLANG_COMPILER_ID_REGEX})
|
||||
set(CMAKE_COMPILER_IS_CLANG 1)
|
||||
endif()
|
||||
|
||||
if("${CMAKE_CXX_COMPILER}" MATCHES "clang(\\+\\+)?$"
|
||||
OR "${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS}" MATCHES "__clang__"
|
||||
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES ${CLANG_COMPILER_ID_REGEX})
|
||||
set(CMAKE_COMPILER_IS_CLANGXX 1)
|
||||
endif()
|
||||
|
||||
@ -253,6 +254,15 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
|
||||
endif()
|
||||
|
||||
if(WITH_COVERAGE AND CMAKE_COMPILER_IS_CLANGXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
|
||||
# then:
|
||||
# $ llvm-profdata merge -sparse default.profraw -o default.profdata
|
||||
# $ llvm-cov show ./tests/${the_test_binary} \
|
||||
# -format=html -instr-profile=default.profdata -output-dir=./coverages \
|
||||
# `find src -iname '*.h' -or -iname '*.cpp'`
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align")
|
||||
endif()
|
||||
@ -276,7 +286,7 @@ if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9.
|
||||
add_gcc_compiler_cxxflags("-fsized-deallocation")
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
if(APPLE AND CMAKE_COMPILER_IS_CLANGXX)
|
||||
add_gcc_compiler_cxxflags("-stdlib=libc++")
|
||||
endif()
|
||||
|
||||
|
@ -619,9 +619,9 @@ bool AutoType::windowMatches(const QString& windowTitle, const QString& windowPa
|
||||
if (windowPattern.startsWith("//") && windowPattern.endsWith("//") && windowPattern.size() >= 4) {
|
||||
QRegExp regExp(windowPattern.mid(2, windowPattern.size() - 4), Qt::CaseInsensitive, QRegExp::RegExp2);
|
||||
return (regExp.indexIn(windowTitle) != -1);
|
||||
} else {
|
||||
return WildcardMatcher(windowTitle).match(windowPattern);
|
||||
}
|
||||
return WildcardMatcher(windowTitle).match(windowPattern);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,10 +1,6 @@
|
||||
set(autotype_mac_SOURCES AutoTypeMac.cpp)
|
||||
|
||||
set(autotype_mac_mm_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/gui/macutils/AppKitImpl.mm
|
||||
${CMAKE_SOURCE_DIR}/src/gui/macutils/MacUtils.cpp)
|
||||
|
||||
add_library(keepassx-autotype-cocoa MODULE ${autotype_mac_SOURCES} ${autotype_mac_mm_SOURCES})
|
||||
add_library(keepassx-autotype-cocoa MODULE ${autotype_mac_SOURCES})
|
||||
set_target_properties(keepassx-autotype-cocoa PROPERTIES LINK_FLAGS "-framework Foundation -framework AppKit -framework Carbon")
|
||||
target_link_libraries(keepassx-autotype-cocoa ${PROGNAME} Qt5::Core Qt5::Widgets)
|
||||
|
||||
|
@ -340,7 +340,7 @@ QJsonObject BrowserAction::handleSetLogin(const QJsonObject& json, const QString
|
||||
QJsonObject message = buildMessage(newNonce);
|
||||
message["count"] = QJsonValue::Null;
|
||||
message["entries"] = QJsonValue::Null;
|
||||
message["error"] = "";
|
||||
message["error"] = QString("");
|
||||
message["hash"] = hash;
|
||||
|
||||
return buildResponse(action, message, newNonce);
|
||||
|
@ -417,7 +417,7 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id,
|
||||
|
||||
// Fill the list
|
||||
for (Entry* entry : pwEntries) {
|
||||
result << prepareEntry(entry);
|
||||
result.append(prepareEntry(entry));
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -825,7 +825,7 @@ QJsonObject BrowserService::prepareEntry(const Entry* entry)
|
||||
if (key.startsWith(QLatin1String("KPH: "))) {
|
||||
QJsonObject sField;
|
||||
sField[key] = entry->resolveMultiplePlaceholders(attr->value(key));
|
||||
stringFields << sField;
|
||||
stringFields.append(sField);
|
||||
}
|
||||
}
|
||||
res["stringFields"] = stringFields;
|
||||
|
@ -299,9 +299,9 @@ QJsonObject HostInstaller::constructFile(SupportedBrowsers browser, const bool&
|
||||
|
||||
QJsonObject script;
|
||||
script["name"] = HOST_NAME;
|
||||
script["description"] = "KeePassXC integration with native messaging support";
|
||||
script["description"] = QString("KeePassXC integration with native messaging support");
|
||||
script["path"] = path;
|
||||
script["type"] = "stdio";
|
||||
script["type"] = QString("stdio");
|
||||
|
||||
QJsonArray arr;
|
||||
if (browser == SupportedBrowsers::FIREFOX || browser == SupportedBrowsers::TOR_BROWSER) {
|
||||
|
@ -102,7 +102,7 @@ void NativeMessagingBase::readNativeMessages()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
quint32 length = 0;
|
||||
while (m_running.load() && !std::cin.eof()) {
|
||||
while (m_running.load() != 0 && !std::cin.eof()) {
|
||||
length = 0;
|
||||
std::cin.read(reinterpret_cast<char*>(&length), 4);
|
||||
readStdIn(length);
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef NATIVEMESSAGINGBASE_H
|
||||
#define NATIVEMESSAGINGBASE_H
|
||||
|
||||
#include <QAtomicInteger>
|
||||
#include <QAtomicInt>
|
||||
#include <QFuture>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@ -60,7 +60,7 @@ protected:
|
||||
QString getLocalServerPath() const;
|
||||
|
||||
protected:
|
||||
QAtomicInteger<quint8> m_running;
|
||||
QAtomicInt m_running;
|
||||
QSharedPointer<QSocketNotifier> m_notifier;
|
||||
QFuture<void> m_future;
|
||||
};
|
||||
|
@ -35,9 +35,9 @@ NativeMessagingHost::NativeMessagingHost(DatabaseTabWidget* parent, const bool e
|
||||
{
|
||||
m_localServer.reset(new QLocalServer(this));
|
||||
m_localServer->setSocketOptions(QLocalServer::UserAccessOption);
|
||||
m_running.store(false);
|
||||
m_running.store(0);
|
||||
|
||||
if (browserSettings()->isEnabled() && !m_running) {
|
||||
if (browserSettings()->isEnabled() && m_running.load() == 0) {
|
||||
run();
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ int NativeMessagingHost::init()
|
||||
void NativeMessagingHost::run()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (!m_running.load() && init() == -1) {
|
||||
if (m_running.load() == 0 && init() == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ void NativeMessagingHost::run()
|
||||
browserSettings()->useCustomProxy() ? browserSettings()->customProxyLocation() : "");
|
||||
}
|
||||
|
||||
m_running.store(true);
|
||||
m_running.store(1);
|
||||
#ifdef Q_OS_WIN
|
||||
m_future =
|
||||
QtConcurrent::run(this, static_cast<void (NativeMessagingHost::*)()>(&NativeMessagingHost::readNativeMessages));
|
||||
@ -100,7 +100,7 @@ void NativeMessagingHost::stop()
|
||||
databaseLocked();
|
||||
QMutexLocker locker(&m_mutex);
|
||||
m_socketList.clear();
|
||||
m_running.testAndSetOrdered(true, false);
|
||||
m_running.testAndSetOrdered(1, 0);
|
||||
m_future.waitForFinished();
|
||||
m_localServer->close();
|
||||
}
|
||||
@ -210,13 +210,13 @@ void NativeMessagingHost::disconnectSocket()
|
||||
void NativeMessagingHost::databaseLocked()
|
||||
{
|
||||
QJsonObject response;
|
||||
response["action"] = "database-locked";
|
||||
response["action"] = QString("database-locked");
|
||||
sendReplyToAllClients(response);
|
||||
}
|
||||
|
||||
void NativeMessagingHost::databaseUnlocked()
|
||||
{
|
||||
QJsonObject response;
|
||||
response["action"] = "database-unlocked";
|
||||
response["action"] = QString("database-unlocked");
|
||||
sendReplyToAllClients(response);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ NativeMessagingHost::NativeMessagingHost()
|
||||
setsockopt(socketDesc, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&max), sizeof(max));
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
m_running.store(true);
|
||||
m_running.store(1);
|
||||
m_future = QtConcurrent::run(this, &NativeMessagingHost::readNativeMessages);
|
||||
#endif
|
||||
connect(m_localSocket, SIGNAL(readyRead()), this, SLOT(newLocalMessage()));
|
||||
@ -56,7 +56,7 @@ void NativeMessagingHost::readNativeMessages()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
quint32 length = 0;
|
||||
while (m_running.load() && !std::cin.eof()) {
|
||||
while (m_running.load() == 1 && !std::cin.eof()) {
|
||||
length = 0;
|
||||
std::cin.read(reinterpret_cast<char*>(&length), 4);
|
||||
if (!readStdIn(length)) {
|
||||
@ -128,6 +128,6 @@ void NativeMessagingHost::deleteSocket()
|
||||
void NativeMessagingHost::socketStateChanged(QLocalSocket::LocalSocketState socketState)
|
||||
{
|
||||
if (socketState == QLocalSocket::UnconnectedState || socketState == QLocalSocket::ClosingState) {
|
||||
m_running.testAndSetOrdered(true, false);
|
||||
m_running.testAndSetOrdered(1, 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user