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
This commit is contained in:
Ikalco 2024-12-18 19:56:01 -06:00 committed by GitHub
parent 7c43eed2c1
commit 5b714f05f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 59 additions and 57 deletions

View file

@ -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);
}

View file

@ -142,7 +142,7 @@ std::string CHyprCtl::getMonitorData(Hyprutils::Memory::CSharedPointer<CMonitor>
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<IKeyboard> 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<int>(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;

View file

@ -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<eIconBackend, 2>{ICONS_BACKEND_NF, ICONS_BACKEND_FA};
for (auto iconID : eIconBackendChecks) {

View file

@ -473,7 +473,7 @@ PHLWINDOW CWindow::x11TransientFor() {
return nullptr;
}
void unregisterVar(void* ptr) {
static void unregisterVar(void* ptr) {
((CBaseAnimatedVariable*)ptr)->unregister();
}

View file

@ -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;

View file

@ -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;

View file

@ -8,7 +8,7 @@ class CGradientValueData;
struct SWindowRenderLayoutHints {
bool isBorderGradient = false;
CGradientValueData* borderGradient;
CGradientValueData* borderGradient = nullptr;
};
struct SLayoutMessageHeader {

View file

@ -2,6 +2,7 @@
#include <cmath>
#include <csignal>
#include <print>
#include <utility>
#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); \
}

View file

@ -18,7 +18,7 @@ using namespace Hyprutils::String;
#include <string>
#include <filesystem>
void help() {
static void help() {
std::println("usage: Hyprland [arg [...]].\n");
std::println(R"(Arguments:
--help -h - Show this message again

View file

@ -10,7 +10,7 @@
#include <hyprgraphics/color/Color.hpp>
int wlTick(SP<CEventLoopTimer> self, void* data) {
static int wlTick(SP<CEventLoopTimer> self, void* data) {
if (g_pAnimationManager)
g_pAnimationManager->onTicked();

View file

@ -299,7 +299,7 @@ bool CKeybindManager::ensureMouseBindState() {
return false;
}
void updateRelativeCursorCoords() {
static void updateRelativeCursorCoords() {
static auto PNOWARPS = CConfigValue<Hyprlang::INT>("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);
}

View file

@ -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<Hyprlang::INT>("misc:disable_autoreload");

View file

@ -21,7 +21,7 @@ const std::vector<const char*> 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);

View file

@ -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);
}