From 5b714f05f87831e3e930af04649f853d5efb9902 Mon Sep 17 00:00:00 2001 From: Ikalco <73481042+ikalco@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:56:01 -0600 Subject: internal: Make static analysis more happy (#8767) * make functions used in 1 file static * fix invalid substr param -1 * give default initializer to borderGradier * move RASSERT from printf to std::print --- src/Compositor.cpp | 8 ++-- src/debug/HyprCtl.cpp | 79 ++++++++++++++++++----------------- src/debug/HyprNotificationOverlay.cpp | 2 +- src/desktop/Window.cpp | 2 +- src/events/Windows.cpp | 2 +- src/helpers/Monitor.cpp | 2 +- src/layout/IHyprLayout.hpp | 2 +- src/macros.hpp | 3 +- src/main.cpp | 2 +- src/managers/AnimationManager.cpp | 2 +- src/managers/KeybindManager.cpp | 4 +- src/managers/ThreadManager.cpp | 2 +- src/render/OpenGL.cpp | 2 +- src/xwayland/Server.cpp | 4 +- 14 files changed, 59 insertions(+), 57 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index dea8cddf..ba723bdc 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -50,7 +50,7 @@ using namespace Hyprutils::String; using namespace Aquamarine; -int handleCritSignal(int signo, void* data) { +static int handleCritSignal(int signo, void* data) { Debug::log(LOG, "Hyprland received signal {}", signo); if (signo == SIGTERM || signo == SIGINT || signo == SIGKILL) @@ -59,7 +59,7 @@ int handleCritSignal(int signo, void* data) { return 0; } -void handleUnrecoverableSignal(int sig) { +static void handleUnrecoverableSignal(int sig) { // remove our handlers signal(SIGABRT, SIG_DFL); @@ -83,7 +83,7 @@ void handleUnrecoverableSignal(int sig) { abort(); } -void handleUserSignal(int sig) { +static void handleUserSignal(int sig) { if (sig == SIGUSR1) { // means we have to unwind a timed out event throw std::exception(); @@ -103,7 +103,7 @@ static eLogLevel aqLevelToHl(Aquamarine::eBackendLogLevel level) { return NONE; } -void aqLog(Aquamarine::eBackendLogLevel level, std::string msg) { +static void aqLog(Aquamarine::eBackendLogLevel level, std::string msg) { Debug::log(aqLevelToHl(level), "[AQ] {}", msg); } diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 2d17b2ae..da0b2e28 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -142,7 +142,7 @@ std::string CHyprCtl::getMonitorData(Hyprutils::Memory::CSharedPointer return result; } -std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); auto allMonitors = false; @@ -269,7 +269,7 @@ std::string CHyprCtl::getWindowData(PHLWINDOW w, eHyprCtlOutputFormat format) { } } -std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; if (format == eHyprCtlOutputFormat::FORMAT_JSON) { result += "["; @@ -368,7 +368,8 @@ static std::string getWorkspaceRuleData(const SWorkspaceRule& r, eHyprCtlOutputF return result; } } -std::string activeWorkspaceRequest(eHyprCtlOutputFormat format, std::string request) { + +static std::string activeWorkspaceRequest(eHyprCtlOutputFormat format, std::string request) { if (!g_pCompositor->m_pLastMonitor) return "unsafe state"; @@ -381,7 +382,7 @@ std::string activeWorkspaceRequest(eHyprCtlOutputFormat format, std::string requ return CHyprCtl::getWorkspaceData(w, format); } -std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; if (format == eHyprCtlOutputFormat::FORMAT_JSON) { @@ -402,7 +403,7 @@ std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request) return result; } -std::string workspaceRulesRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string workspaceRulesRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; if (format == eHyprCtlOutputFormat::FORMAT_JSON) { result += "["; @@ -422,7 +423,7 @@ std::string workspaceRulesRequest(eHyprCtlOutputFormat format, std::string reque return result; } -std::string activeWindowRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string activeWindowRequest(eHyprCtlOutputFormat format, std::string request) { const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!validMapped(PWINDOW)) @@ -436,7 +437,7 @@ std::string activeWindowRequest(eHyprCtlOutputFormat format, std::string request return result; } -std::string layersRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string layersRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; if (format == eHyprCtlOutputFormat::FORMAT_JSON) { @@ -510,7 +511,7 @@ std::string layersRequest(eHyprCtlOutputFormat format, std::string request) { return result; } -std::string layoutsRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string layoutsRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; if (format == eHyprCtlOutputFormat::FORMAT_JSON) { result += "["; @@ -532,7 +533,7 @@ std::string layoutsRequest(eHyprCtlOutputFormat format, std::string request) { return result; } -std::string configErrorsRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string configErrorsRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; std::string currErrors = g_pConfigManager->getErrors(); CVarList errLines(currErrors, 0, '\n'); @@ -555,7 +556,7 @@ std::string configErrorsRequest(eHyprCtlOutputFormat format, std::string request return result; } -std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; auto getModState = [](SP keyboard, const char* xkbModName) -> bool { @@ -725,7 +726,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) { return result; } -std::string animationsRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string animationsRequest(eHyprCtlOutputFormat format, std::string request) { std::string ret = ""; if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) { ret += "animations:\n"; @@ -778,7 +779,7 @@ std::string animationsRequest(eHyprCtlOutputFormat format, std::string request) return ret; } -std::string rollinglogRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string rollinglogRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; if (format == eHyprCtlOutputFormat::FORMAT_JSON) { @@ -792,7 +793,7 @@ std::string rollinglogRequest(eHyprCtlOutputFormat format, std::string request) return result; } -std::string globalShortcutsRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string globalShortcutsRequest(eHyprCtlOutputFormat format, std::string request) { std::string ret = ""; const auto SHORTCUTS = PROTO::globalShortcuts->getAllShortcuts(); if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) { @@ -815,7 +816,7 @@ std::string globalShortcutsRequest(eHyprCtlOutputFormat format, std::string requ return ret; } -std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) { std::string ret = ""; if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) { for (auto const& kb : g_pKeybindManager->m_vKeybinds) { @@ -1018,7 +1019,7 @@ std::string systemInfoRequest(eHyprCtlOutputFormat format, std::string request) return result; } -std::string dispatchRequest(eHyprCtlOutputFormat format, std::string in) { +static std::string dispatchRequest(eHyprCtlOutputFormat format, std::string in) { // get rid of the dispatch keyword in = in.substr(in.find_first_of(' ') + 1); @@ -1039,7 +1040,7 @@ std::string dispatchRequest(eHyprCtlOutputFormat format, std::string in) { return res.success ? "ok" : res.error; } -std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) { +static std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) { // Find the first space to strip the keyword keyword auto const firstSpacePos = in.find_first_of(' '); if (firstSpacePos == std::string::npos) // Handle the case where there's no space found (invalid input) @@ -1105,7 +1106,7 @@ std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) { return retval; } -std::string reloadRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string reloadRequest(eHyprCtlOutputFormat format, std::string request) { const auto REQMODE = request.substr(request.find_last_of(' ') + 1); @@ -1120,17 +1121,17 @@ std::string reloadRequest(eHyprCtlOutputFormat format, std::string request) { return "ok"; } -std::string killRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string killRequest(eHyprCtlOutputFormat format, std::string request) { g_pInputManager->setClickMode(CLICKMODE_KILL); return "ok"; } -std::string splashRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string splashRequest(eHyprCtlOutputFormat format, std::string request) { return g_pCompositor->m_szCurrentSplash; } -std::string cursorPosRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string cursorPosRequest(eHyprCtlOutputFormat format, std::string request) { const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal().floor(); if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) { @@ -1148,7 +1149,7 @@ std::string cursorPosRequest(eHyprCtlOutputFormat format, std::string request) { return "error"; } -std::string dispatchBatch(eHyprCtlOutputFormat format, std::string request) { +static std::string dispatchBatch(eHyprCtlOutputFormat format, std::string request) { // split by ; request = request.substr(9); @@ -1182,7 +1183,7 @@ std::string dispatchBatch(eHyprCtlOutputFormat format, std::string request) { return reply.substr(0, std::max(static_cast(reply.size() - DELIMITER.size()), 0)); } -std::string dispatchSetCursor(eHyprCtlOutputFormat format, std::string request) { +static std::string dispatchSetCursor(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); const auto SIZESTR = vars[vars.size() - 1]; @@ -1206,7 +1207,7 @@ std::string dispatchSetCursor(eHyprCtlOutputFormat format, std::string request) return "ok"; } -std::string switchXKBLayoutRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string switchXKBLayoutRequest(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); const auto KB = vars[1]; @@ -1281,7 +1282,7 @@ std::string switchXKBLayoutRequest(eHyprCtlOutputFormat format, std::string requ return "ok"; } -std::string dispatchSeterror(eHyprCtlOutputFormat format, std::string request) { +static std::string dispatchSeterror(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); std::string errorMessage = ""; @@ -1310,12 +1311,12 @@ std::string dispatchSeterror(eHyprCtlOutputFormat format, std::string request) { return "ok"; } -std::string dispatchSetProp(eHyprCtlOutputFormat format, std::string request) { - auto result = g_pKeybindManager->m_mDispatchers["setprop"](request.substr(request.find_first_of(' ') + 1, -1)); +static std::string dispatchSetProp(eHyprCtlOutputFormat format, std::string request) { + auto result = g_pKeybindManager->m_mDispatchers["setprop"](request.substr(request.find_first_of(' ') + 1)); return "DEPRECATED: use hyprctl dispatch setprop instead" + (result.success ? "" : "\n" + result.error); } -std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request) { +static std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request) { std::string curitem = ""; auto nextItem = [&]() { @@ -1371,7 +1372,7 @@ std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request) return "invalid type (internal error)"; } -std::string decorationRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string decorationRequest(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); const auto PWINDOW = g_pCompositor->getWindowByRegex(vars[1]); @@ -1397,7 +1398,7 @@ std::string decorationRequest(eHyprCtlOutputFormat format, std::string request) return result; } -std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) { +static std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); if (vars.size() < 2) @@ -1452,7 +1453,7 @@ std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) { return "ok"; } -std::string dispatchPlugin(eHyprCtlOutputFormat format, std::string request) { +static std::string dispatchPlugin(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); if (vars.size() < 2) @@ -1521,7 +1522,7 @@ std::string dispatchPlugin(eHyprCtlOutputFormat format, std::string request) { return "ok"; } -std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { +static std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); if (vars.size() < 5) @@ -1576,7 +1577,7 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { return "ok"; } -std::string dispatchDismissNotify(eHyprCtlOutputFormat format, std::string request) { +static std::string dispatchDismissNotify(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); int amount = -1; @@ -1596,7 +1597,7 @@ std::string dispatchDismissNotify(eHyprCtlOutputFormat format, std::string reque return "ok"; } -std::string getIsLocked(eHyprCtlOutputFormat format, std::string request) { +static std::string getIsLocked(eHyprCtlOutputFormat format, std::string request) { std::string lockedStr = g_pSessionLockManager->isSessionLocked() ? "true" : "false"; if (format == eHyprCtlOutputFormat::FORMAT_JSON) lockedStr = std::format(R"#( @@ -1608,7 +1609,7 @@ std::string getIsLocked(eHyprCtlOutputFormat format, std::string request) { return lockedStr; } -std::string getDescriptions(eHyprCtlOutputFormat format, std::string request) { +static std::string getDescriptions(eHyprCtlOutputFormat format, std::string request) { std::string json = "{"; const auto& DESCS = g_pConfigManager->getAllDescriptions(); @@ -1623,7 +1624,7 @@ std::string getDescriptions(eHyprCtlOutputFormat format, std::string request) { return json; } -std::string submapRequest(eHyprCtlOutputFormat format, std::string request) { +static std::string submapRequest(eHyprCtlOutputFormat format, std::string request) { std::string submap = g_pKeybindManager->getCurrentSubmap(); if (submap.empty()) submap = "default"; @@ -1792,7 +1793,7 @@ std::string CHyprCtl::makeDynamicCall(const std::string& input) { return getReply(input); } -bool successWrite(int fd, const std::string& data, bool needLog = true) { +static bool successWrite(int fd, const std::string& data, bool needLog = true) { if (write(fd, data.c_str(), data.length()) > 0) return true; @@ -1805,7 +1806,7 @@ bool successWrite(int fd, const std::string& data, bool needLog = true) { return false; } -void runWritingDebugLogThread(const int conn) { +static void runWritingDebugLogThread(const int conn) { using namespace std::chrono_literals; Debug::log(LOG, "In followlog thread, got connection, start writing: {}", conn); //will be finished, when reading side close connection @@ -1828,11 +1829,11 @@ void runWritingDebugLogThread(const int conn) { }).detach(); } -bool isFollowUpRollingLogRequest(const std::string& request) { +static bool isFollowUpRollingLogRequest(const std::string& request) { return request.contains("rollinglog") && request.contains("f"); } -int hyprCtlFDTick(int fd, uint32_t mask, void* data) { +static int hyprCtlFDTick(int fd, uint32_t mask, void* data) { if (mask & WL_EVENT_ERROR || mask & WL_EVENT_HANGUP) return 0; diff --git a/src/debug/HyprNotificationOverlay.cpp b/src/debug/HyprNotificationOverlay.cpp index 153d2395..7bcfad82 100644 --- a/src/debug/HyprNotificationOverlay.cpp +++ b/src/debug/HyprNotificationOverlay.cpp @@ -4,7 +4,7 @@ #include "../Compositor.hpp" #include "../config/ConfigValue.hpp" -inline auto iconBackendFromLayout(PangoLayout* layout) { +static inline auto iconBackendFromLayout(PangoLayout* layout) { // preference: Nerd > FontAwesome > text auto eIconBackendChecks = std::array{ICONS_BACKEND_NF, ICONS_BACKEND_FA}; for (auto iconID : eIconBackendChecks) { diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index c0752224..696bfc5b 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -473,7 +473,7 @@ PHLWINDOW CWindow::x11TransientFor() { return nullptr; } -void unregisterVar(void* ptr) { +static void unregisterVar(void* ptr) { ((CBaseAnimatedVariable*)ptr)->unregister(); } diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index edc29ed3..437301b7 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -27,7 +27,7 @@ using namespace Hyprutils::String; // // // ------------------------------------------------------------ // -void setAnimToMove(void* data) { +static void setAnimToMove(void* data) { auto* const PANIMCFG = g_pConfigManager->getAnimationPropertyConfig("windowsMove"); CBaseAnimatedVariable* animvar = (CBaseAnimatedVariable*)data; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 8d1597be..33ec3abe 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -24,7 +24,7 @@ using namespace Hyprutils::String; using namespace Hyprutils::Utils; -int ratHandler(void* data) { +static int ratHandler(void* data) { g_pHyprRenderer->renderMonitor(((CMonitor*)data)->self.lock()); return 1; diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index c5de8339..ab188b9b 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -8,7 +8,7 @@ class CGradientValueData; struct SWindowRenderLayoutHints { bool isBorderGradient = false; - CGradientValueData* borderGradient; + CGradientValueData* borderGradient = nullptr; }; struct SLayoutMessageHeader { diff --git a/src/macros.hpp b/src/macros.hpp index 4a319569..de2fd009 100644 --- a/src/macros.hpp +++ b/src/macros.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "helpers/memory/Memory.hpp" @@ -49,7 +50,7 @@ Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n{}\n\nat: line {} in {}", \ std::format(reason, ##__VA_ARGS__), __LINE__, \ ([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })()); \ - printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \ + std::print("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \ raise(SIGABRT); \ } diff --git a/src/main.cpp b/src/main.cpp index 6b6f9063..ebae055b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ using namespace Hyprutils::String; #include #include -void help() { +static void help() { std::println("usage: Hyprland [arg [...]].\n"); std::println(R"(Arguments: --help -h - Show this message again diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index c8f7ecdf..e3309282 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -10,7 +10,7 @@ #include -int wlTick(SP self, void* data) { +static int wlTick(SP self, void* data) { if (g_pAnimationManager) g_pAnimationManager->onTicked(); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index fec608f1..e1ad7d60 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -299,7 +299,7 @@ bool CKeybindManager::ensureMouseBindState() { return false; } -void updateRelativeCursorCoords() { +static void updateRelativeCursorCoords() { static auto PNOWARPS = CConfigValue("cursor:no_warps"); if (*PNOWARPS) @@ -1095,7 +1095,7 @@ SDispatchResult CKeybindManager::toggleActivePseudo(std::string args) { return {}; } -SWorkspaceIDName getWorkspaceToChangeFromArgs(std::string args, PHLWORKSPACE PCURRENTWORKSPACE) { +static SWorkspaceIDName getWorkspaceToChangeFromArgs(std::string args, PHLWORKSPACE PCURRENTWORKSPACE) { if (!args.starts_with("previous")) { return getWorkspaceIDNameFromString(args); } diff --git a/src/managers/ThreadManager.cpp b/src/managers/ThreadManager.cpp index ce15688d..bd124c99 100644 --- a/src/managers/ThreadManager.cpp +++ b/src/managers/ThreadManager.cpp @@ -3,7 +3,7 @@ #include "../Compositor.hpp" #include "../config/ConfigValue.hpp" -int handleTimer(void* data) { +static int handleTimer(void* data) { const auto PTM = (CThreadManager*)data; static auto PDISABLECFGRELOAD = CConfigValue("misc:disable_autoreload"); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 9511123c..4339fd40 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -21,7 +21,7 @@ const std::vector ASSET_PATHS = { "/usr/local/share", }; -inline void loadGLProc(void* pProc, const char* name) { +static inline void loadGLProc(void* pProc, const char* name) { void* proc = (void*)eglGetProcAddress(name); if (proc == nullptr) { Debug::log(CRIT, "[Tracy GPU Profiling] eglGetProcAddress({}) failed", name); diff --git a/src/xwayland/Server.cpp b/src/xwayland/Server.cpp index 9d6b3bcb..b1f02cd3 100644 --- a/src/xwayland/Server.cpp +++ b/src/xwayland/Server.cpp @@ -51,13 +51,13 @@ static bool setCloseOnExec(int fd, bool cloexec) { return true; } -void cleanUpSocket(int fd, const char* path) { +static void cleanUpSocket(int fd, const char* path) { close(fd); if (path[0]) unlink(path); } -inline void closeSocketSafely(int& fd) { +static inline void closeSocketSafely(int& fd) { if (fd >= 0) close(fd); } -- cgit v1.2.3