Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.7] Ci/clang tidy checks init variables #5490

Merged
merged 7 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)
cmake_policy(SET CMP0071 NEW) # Enable use of QtQuick compiler/generated code

find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
if (CLANG_TIDY_EXE)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE} -checks=-*,modernize-use-auto,modernize-use-using,modernize-use-nodiscard,modernize-use-nullptr,modernize-use-override,cppcoreguidelines-pro-type-static-cast-downcast,modernize-use-default-member-init,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-init-variables)
endif()

project(client)

include(FeatureSummary)
Expand Down
4 changes: 2 additions & 2 deletions shell_integration/windows/NCContextMenu/NCContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ IFACEMETHODIMP NCContextMenu::QueryInterface(REFIID riid, void **ppv)
{
QITABENT(NCContextMenu, IContextMenu),
QITABENT(NCContextMenu, IShellExtInit),
{ 0 },
{ nullptr },
};
return QISearch(this, qit, riid, ppv);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ IFACEMETHODIMP NCContextMenu::Initialize(

if (SUCCEEDED(pDataObj->GetData(&fe, &stm))) {
// Get an HDROP handle.
HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal));
const auto hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal));
if (hDrop) {
UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, nullptr, 0);
for (UINT i = 0; i < nFiles; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ NCContextMenuFactory::~NCContextMenuFactory()

IFACEMETHODIMP NCContextMenuFactory::QueryInterface(REFIID riid, void **ppv)
{
static const QITAB qit[] = { QITABENT(NCContextMenuFactory, IClassFactory), { 0 }, };
static const QITAB qit[] = { QITABENT(NCContextMenuFactory, IClassFactory), { nullptr }, };
return QISearch(this, qit, riid, ppv);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ IFACEMETHODIMP NCContextMenuFactory::CreateInstance(IUnknown *pUnkOuter, REFIID
hr = E_OUTOFMEMORY;

// Create the COM component.
NCContextMenu *pExt = new (std::nothrow) NCContextMenu();
auto pExt = new (std::nothrow) NCContextMenu();
if (pExt) {
// Query the specified interface.
hr = pExt->QueryInterface(riid, ppv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace {

HRESULT SetHKCRRegistryKeyAndValue(PCWSTR pszSubKey, PCWSTR pszValueName, PCWSTR pszData)
{
HRESULT hr;
HRESULT hr = 0;
HKEY hKey = nullptr;

// Creates the specified registry key. If the key already exists, the
Expand All @@ -31,8 +31,8 @@ HRESULT SetHKCRRegistryKeyAndValue(PCWSTR pszSubKey, PCWSTR pszValueName, PCWSTR

if (SUCCEEDED(hr))
{
DWORD cbData;
const BYTE * lpData;
DWORD cbData = 0;
const BYTE * lpData = nullptr;

if (pszData)
{
Expand All @@ -43,7 +43,7 @@ HRESULT SetHKCRRegistryKeyAndValue(PCWSTR pszSubKey, PCWSTR pszValueName, PCWSTR
else
{
cbData = 0;
lpData = NULL;
lpData = nullptr;
}

hr = HRESULT_FROM_WIN32(RegSetValueEx(hKey, pszValueName, 0,
Expand All @@ -57,7 +57,7 @@ HRESULT SetHKCRRegistryKeyAndValue(PCWSTR pszSubKey, PCWSTR pszValueName, PCWSTR

HRESULT GetHKCRRegistryKeyAndValue(PCWSTR pszSubKey, PCWSTR pszValueName, PWSTR pszData, DWORD cbData)
{
HRESULT hr;
HRESULT hr = 0;
HKEY hKey = nullptr;

// Try to open the specified registry key.
Expand Down Expand Up @@ -85,7 +85,7 @@ HRESULT NCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CL
return E_INVALIDARG;
}

HRESULT hr;
HRESULT hr = 0;

wchar_t szCLSID[MAX_PATH];
StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));
Expand All @@ -100,7 +100,7 @@ HRESULT NCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CL

// Create the HKCR\CLSID\{<CLSID>}\ContextMenuOptIn subkey.
if (SUCCEEDED(hr)) {
hr = SetHKCRRegistryKeyAndValue(szSubkey, L"ContextMenuOptIn", NULL);
hr = SetHKCRRegistryKeyAndValue(szSubkey, L"ContextMenuOptIn", nullptr);
}

// Create the HKCR\CLSID\{<CLSID>}\InprocServer32 key.
Expand Down Expand Up @@ -154,7 +154,7 @@ HRESULT NCContextMenuRegHandler::RegisterShellExtContextMenuHandler(
return E_INVALIDARG;
}

HRESULT hr;
HRESULT hr = 0;

wchar_t szCLSID[MAX_PATH];
StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));
Expand Down Expand Up @@ -198,7 +198,7 @@ HRESULT NCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(
return E_INVALIDARG;
}

HRESULT hr;
HRESULT hr = 0;

wchar_t szSubkey[MAX_PATH];

Expand Down
6 changes: 3 additions & 3 deletions shell_integration/windows/NCContextMenu/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
{
HRESULT hr;
HRESULT hr = 0;
GUID guid;

hr = CLSIDFromString(CONTEXT_MENU_GUID, (LPCLSID)&guid);
Expand All @@ -54,7 +54,7 @@ STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
if (IsEqualCLSID(guid, rclsid)) {
hr = E_OUTOFMEMORY;

NCContextMenuFactory *pClassFactory = new NCContextMenuFactory();
auto pClassFactory = new NCContextMenuFactory();
if (pClassFactory) {
hr = pClassFactory->QueryInterface(riid, ppv);
pClassFactory->Release();
Expand All @@ -71,7 +71,7 @@ STDAPI DllCanUnloadNow(void)

STDAPI DllRegisterServer(void)
{
HRESULT hr;
HRESULT hr = 0;
GUID guid;

hr = CLSIDFromString(CONTEXT_MENU_GUID, (LPCLSID)&guid);
Expand Down
2 changes: 1 addition & 1 deletion shell_integration/windows/NCOverlays/DllMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ HRESULT CreateFactory(REFIID riid, void **ppv, int state)
{
HRESULT hResult = E_OUTOFMEMORY;

NCOverlayFactory* ncOverlayFactory = new NCOverlayFactory(state);
auto ncOverlayFactory = new NCOverlayFactory(state);

if (ncOverlayFactory) {
hResult = ncOverlayFactory->QueryInterface(riid, ppv);
Expand Down
2 changes: 1 addition & 1 deletion shell_integration/windows/NCOverlays/NCOverlayFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ IFACEMETHODIMP NCOverlayFactory::CreateInstance(
if (pUnkOuter) { return hResult; }

hResult = E_OUTOFMEMORY;
NCOverlay *lrOverlay = new (std::nothrow) NCOverlay(_state);
auto lrOverlay = new (std::nothrow) NCOverlay(_state);
if (!lrOverlay) { return hResult; }

hResult = lrOverlay->QueryInterface(riid, ppv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace std;

HRESULT NCOverlayRegistrationHandler::MakeRegistryEntries(const CLSID& clsid, PCWSTR friendlyName)
{
HRESULT hResult;
HRESULT hResult = 0;
HKEY shellOverlayKey = nullptr;
// the key may not exist yet
hResult = HRESULT_FROM_WIN32(RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_OVERLAY_KEY, 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &shellOverlayKey, nullptr));
Expand Down Expand Up @@ -62,7 +62,7 @@ HRESULT NCOverlayRegistrationHandler::MakeRegistryEntries(const CLSID& clsid, PC

HRESULT NCOverlayRegistrationHandler::RemoveRegistryEntries(PCWSTR friendlyName)
{
HRESULT hResult;
HRESULT hResult = 0;
HKEY shellOverlayKey = nullptr;
hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_OVERLAY_KEY, 0, KEY_WRITE, &shellOverlayKey));

Expand All @@ -87,7 +87,7 @@ HRESULT NCOverlayRegistrationHandler::RegisterCOMObject(PCWSTR modulePath, PCWST

wchar_t stringCLSID[MAX_PATH];
StringFromGUID2(clsid, stringCLSID, ARRAYSIZE(stringCLSID));
HRESULT hResult;
HRESULT hResult = 0;
HKEY hKey = nullptr;

hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_CLASSES_ROOT, REGISTRY_CLSID, 0, KEY_WRITE, &hKey));
Expand Down Expand Up @@ -139,7 +139,7 @@ HRESULT NCOverlayRegistrationHandler::UnregisterCOMObject(const CLSID& clsid)
wchar_t stringCLSID[MAX_PATH];

StringFromGUID2(clsid, stringCLSID, ARRAYSIZE(stringCLSID));
HRESULT hResult;
HRESULT hResult = 0;
HKEY hKey = nullptr;
hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_CLASSES_ROOT, REGISTRY_CLSID, 0, DELETE, &hKey));
if (!SUCCEEDED(hResult)) {
Expand Down
4 changes: 2 additions & 2 deletions shell_integration/windows/NCUtil/CommunicationSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ bool CommunicationSocket::ReadLine(wstring* response)
return true;
}

std::array<char, 128> resp_utf8;
std::array<char, 128> resp_utf8 = {};
DWORD numBytesRead = 0;
DWORD totalBytesAvailable = 0;

if (!PeekNamedPipe(_pipe, nullptr, 0, 0, &totalBytesAvailable, 0)) {
if (!PeekNamedPipe(_pipe, nullptr, 0, nullptr, &totalBytesAvailable, nullptr)) {
Close();
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion shell_integration/windows/NCUtil/CommunicationSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class __declspec(dllexport) CommunicationSocket
private:
HANDLE _pipe;
std::vector<char> _buffer;
bool _connected;
bool _connected = false;
};

#endif
8 changes: 4 additions & 4 deletions src/3rdparty/kirigami/wheelhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ bool WheelHandler::eventFilter(QObject *watched, QEvent *event)
m_horizontalScrollBar->setProperty("interactive", true);
}
}
QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
auto *wheelEvent = dynamic_cast<QWheelEvent *>(event);

// NOTE: On X11 with libinput, pixelDelta is identical to angleDelta when using a mouse that shouldn't use pixelDelta.
// If faulty pixelDelta, reset pixelDelta to (0,0).
Expand Down Expand Up @@ -555,7 +555,7 @@ bool WheelHandler::eventFilter(QObject *watched, QEvent *event)

case QEvent::MouseButtonPress: {
// NOTE: Flickable does not handle touch events, only synthesized mouse events
m_wasTouched = static_cast<QMouseEvent *>(event)->source() != Qt::MouseEventNotSynthesized;
m_wasTouched = dynamic_cast<QMouseEvent *>(event)->source() != Qt::MouseEventNotSynthesized;
if (!m_filterMouseEvents) {
break;
}
Expand All @@ -577,7 +577,7 @@ bool WheelHandler::eventFilter(QObject *watched, QEvent *event)
if (!m_filterMouseEvents) {
break;
}
if (static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized && item == m_flickable) {
if (dynamic_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized && item == m_flickable) {
return true;
}
break;
Expand All @@ -603,7 +603,7 @@ bool WheelHandler::eventFilter(QObject *watched, QEvent *event)
if (!m_keyNavigationEnabled) {
break;
}
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);
bool horizontalScroll = keyEvent->modifiers() & m_defaultHorizontalScrollModifiers;
switch (keyEvent->key()) {
case Qt::Key_Up: return scrollUp();
Expand Down
2 changes: 1 addition & 1 deletion src/3rdparty/kmessagewidget/kmessagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class KMessageWidgetPrivate
QIcon icon;
bool ignoreShowEventDoingAnimatedShow = false;

KMessageWidget::MessageType messageType;
KMessageWidget::MessageType messageType = KMessageWidget::Positive;
bool wordWrap = false;
QList<QToolButton *> buttons;
QPixmap contentSnapShot;
Expand Down
8 changes: 4 additions & 4 deletions src/3rdparty/qtlockedfile/qtlockedfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ QtLockedFile::QtLockedFile()
: QFile()
{
#ifdef Q_OS_WIN
m_semaphore_hnd = 0;
m_mutex_hnd = 0;
m_semaphore_hnd = nullptr;
m_mutex_hnd = nullptr;
#endif
m_lock_mode = NoLock;
}
Expand All @@ -90,8 +90,8 @@ QtLockedFile::QtLockedFile(const QString &name)
: QFile(name)
{
#ifdef Q_OS_WIN
m_semaphore_hnd = 0;
m_mutex_hnd = 0;
m_semaphore_hnd = nullptr;
m_mutex_hnd = nullptr;
#endif
m_lock_mode = NoLock;
}
Expand Down
32 changes: 16 additions & 16 deletions src/3rdparty/qtlockedfile/qtlockedfile_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ namespace SharedTools {
static QString errorCodeToString(DWORD errorCode)
{
QString result;
char *data = 0;
char *data = nullptr;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
0, errorCode, 0,
(char*)&data, 0, 0);
nullptr, errorCode, 0,
(char*)&data, 0, nullptr);
result = QString::fromLocal8Bit(data);
if (data != 0)
if (data != nullptr)
LocalFree(data);

if (result.endsWith(QLatin1Char('\n')))
Expand All @@ -68,35 +68,35 @@ bool QtLockedFile::lock(LockMode mode, bool block)
if (m_lock_mode != 0)
unlock();

if (m_semaphore_hnd == 0) {
if (m_semaphore_hnd == nullptr) {
QFileInfo fi(*this);
QString sem_name = QString::fromLatin1(SEMAPHORE_PREFIX)
+ fi.absoluteFilePath().toLower();

m_semaphore_hnd = CreateSemaphoreW(0, SEMAPHORE_MAX, SEMAPHORE_MAX,
m_semaphore_hnd = CreateSemaphoreW(nullptr, SEMAPHORE_MAX, SEMAPHORE_MAX,
(TCHAR*)sem_name.utf16());

if (m_semaphore_hnd == 0) {
if (m_semaphore_hnd == nullptr) {
qWarning("QtLockedFile::lock(): CreateSemaphore: %s",
errorCodeToString(GetLastError()).toLatin1().constData());
return false;
}
}

bool gotMutex = false;
int decrement;
int decrement = 0;
if (mode == ReadLock) {
decrement = 1;
} else {
decrement = SEMAPHORE_MAX;
if (m_mutex_hnd == 0) {
if (m_mutex_hnd == nullptr) {
QFileInfo fi(*this);
QString mut_name = QString::fromLatin1(MUTEX_PREFIX)
+ fi.absoluteFilePath().toLower();

m_mutex_hnd = CreateMutexW(nullptr, FALSE, (TCHAR*)mut_name.utf16());

if (m_mutex_hnd == 0) {
if (m_mutex_hnd == nullptr) {
qWarning("QtLockedFile::lock(): CreateMutex: %s",
errorCodeToString(GetLastError()).toLatin1().constData());
return false;
Expand Down Expand Up @@ -153,13 +153,13 @@ bool QtLockedFile::unlock()
if (!isLocked())
return true;

int increment;
int increment = 0;
if (m_lock_mode == ReadLock)
increment = 1;
else
increment = SEMAPHORE_MAX;

DWORD ret = ReleaseSemaphore(m_semaphore_hnd, increment, 0);
DWORD ret = ReleaseSemaphore(m_semaphore_hnd, increment, nullptr);
if (ret == 0) {
qWarning("QtLockedFile::unlock(): ReleaseSemaphore: %s",
errorCodeToString(GetLastError()).toLatin1().constData());
Expand All @@ -175,21 +175,21 @@ QtLockedFile::~QtLockedFile()
{
if (isOpen())
unlock();
if (m_mutex_hnd != 0) {
if (m_mutex_hnd != nullptr) {
DWORD ret = CloseHandle(m_mutex_hnd);
if (ret == 0) {
qWarning("QtLockedFile::~QtLockedFile(): CloseHandle (mutex): %s",
errorCodeToString(GetLastError()).toLatin1().constData());
}
m_mutex_hnd = 0;
m_mutex_hnd = nullptr;
}
if (m_semaphore_hnd != 0) {
if (m_semaphore_hnd != nullptr) {
DWORD ret = CloseHandle(m_semaphore_hnd);
if (ret == 0) {
qWarning("QtLockedFile::~QtLockedFile(): CloseHandle (semaphore): %s",
errorCodeToString(GetLastError()).toLatin1().constData());
}
m_semaphore_hnd = 0;
m_semaphore_hnd = nullptr;
}
}

Expand Down
Loading