From 3d2df1a40a67d150f6ae77246dcdf75da4010f75 Mon Sep 17 00:00:00 2001 From: Jaime Moreira Date: Sat, 7 Mar 2026 17:02:53 -0300 Subject: [PATCH] ARRLEN macro used where appropriate Some consts are actually static --- src/backends/generic/misc.c | 2 +- src/backends/windows/system.c | 10 +++++----- src/client/cl_keyboard.c | 5 ++--- src/client/input/sdl2.c | 4 ++-- src/client/input/sdl3.c | 4 ++-- src/common/filesystem.c | 5 ++--- src/game/g_cmds.c | 2 +- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/backends/generic/misc.c b/src/backends/generic/misc.c index 54b8f10e..d9acea5a 100644 --- a/src/backends/generic/misc.c +++ b/src/backends/generic/misc.c @@ -108,7 +108,7 @@ static void SetExecutablePath(char* exePath) int name[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME}; #endif size_t len = PATH_MAX-1; - int ret = sysctl(name, sizeof(name)/sizeof(name[0]), exePath, &len, NULL, 0); + int ret = sysctl(name, ARRLEN(name), exePath, &len, NULL, 0); if(ret != 0) { // an error occured, clear exe path diff --git a/src/backends/windows/system.c b/src/backends/windows/system.c index 61664166..f5bd10b3 100644 --- a/src/backends/windows/system.c +++ b/src/backends/windows/system.c @@ -622,7 +622,7 @@ Sys_Realpath(const char *in, char *out, size_t size) WCHAR win[MAX_OSPATH] = {0}; WCHAR wconverted[MAX_OSPATH] = {0}; - MultiByteToWideChar(CP_UTF8, 0, in, -1, win, sizeof(win)/sizeof(win[0])); + MultiByteToWideChar(CP_UTF8, 0, in, -1, win, ARRLEN(win)); if (_wfullpath(wconverted, win, size) == NULL) { @@ -706,7 +706,7 @@ Sys_GetWorkDir(char *buffer, size_t len) { WCHAR wbuffer[MAX_OSPATH]; - if (GetCurrentDirectoryW(sizeof(wbuffer)/sizeof(wbuffer[0]), wbuffer) != 0) + if (GetCurrentDirectoryW(ARRLEN(wbuffer), wbuffer) != 0) { WideCharToMultiByte(CP_UTF8, 0, wbuffer, -1, buffer, len, NULL, NULL); return; @@ -720,7 +720,7 @@ Sys_SetWorkDir(char *path) { WCHAR wpath[MAX_OSPATH]; - MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, sizeof(wpath)/sizeof(wpath[0])); + MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, ARRLEN(wpath)); if (SetCurrentDirectoryW(wpath) != 0) { @@ -760,8 +760,8 @@ Sys_RedirectStdout(void) snprintf(path_stdout, sizeof(path_stdout), "%s/%s", dir, "stdout.txt"); snprintf(path_stderr, sizeof(path_stderr), "%s/%s", dir, "stderr.txt"); - MultiByteToWideChar(CP_UTF8, 0, path_stdout, -1, wpath_stdout, sizeof(wpath_stdout)/sizeof(wpath_stdout[0])); - MultiByteToWideChar(CP_UTF8, 0, path_stderr, -1, wpath_stderr, sizeof(wpath_stderr)/sizeof( wpath_stderr[0] ) ); + MultiByteToWideChar(CP_UTF8, 0, path_stdout, -1, wpath_stdout, ARRLEN(wpath_stdout)); + MultiByteToWideChar(CP_UTF8, 0, path_stderr, -1, wpath_stderr, ARRLEN(wpath_stderr)); _wfreopen(wpath_stdout, L"w", stdout); _wfreopen(wpath_stderr, L"w", stderr); diff --git a/src/client/cl_keyboard.c b/src/client/cl_keyboard.c index fef1d9ff..2ecf6894 100644 --- a/src/client/cl_keyboard.c +++ b/src/client/cl_keyboard.c @@ -275,8 +275,6 @@ static char *gamepadbtns[] = "TRIG_RIGHT_ALT" }; -#define NUM_GAMEPAD_BTNS (sizeof gamepadbtns / sizeof gamepadbtns[0]) - static char *gpbtns_face[] = { // Xbox @@ -822,6 +820,7 @@ Key_Message(int key) static int Key_StringToKeynum(char *str) { + static const int num_gamepad_btns = ARRLEN(gamepadbtns); keyname_t *kn; int i; @@ -843,7 +842,7 @@ Key_StringToKeynum(char *str) } } - for (i = 0; i < NUM_GAMEPAD_BTNS; i++) + for (i = 0; i < num_gamepad_btns; i++) { if (!Q_stricmp(str, gamepadbtns[i])) { diff --git a/src/client/input/sdl2.c b/src/client/input/sdl2.c index 138bd08f..3ee91d0b 100644 --- a/src/client/input/sdl2.c +++ b/src/client/input/sdl2.c @@ -2804,7 +2804,7 @@ static const joy_preset_t joy_presets[] = { void IN_ApplyJoyPreset(void) { - const int final_preset = ARRLEN(joy_presets) - 1; + static const int final_preset = ARRLEN(joy_presets) - 1; const int i = lroundf(Q_clamp(joy_sensitivity->value, 0, final_preset)); joy_sensitivity->modified = false; @@ -2822,7 +2822,7 @@ IN_ApplyJoyPreset(void) qboolean IN_MatchJoyPreset(void) { - const int num_presets = ARRLEN(joy_presets); + static const int num_presets = ARRLEN(joy_presets); for (int i = 0; i < num_presets; i++) { diff --git a/src/client/input/sdl3.c b/src/client/input/sdl3.c index 9fce7efb..38278860 100644 --- a/src/client/input/sdl3.c +++ b/src/client/input/sdl3.c @@ -2773,7 +2773,7 @@ static const joy_preset_t joy_presets[] = { void IN_ApplyJoyPreset(void) { - const int final_preset = ARRLEN(joy_presets) - 1; + static const int final_preset = ARRLEN(joy_presets) - 1; const int i = lroundf(Q_clamp(joy_sensitivity->value, 0, final_preset)); joy_sensitivity->modified = false; @@ -2791,7 +2791,7 @@ IN_ApplyJoyPreset(void) qboolean IN_MatchJoyPreset(void) { - const int num_presets = ARRLEN(joy_presets); + static const int num_presets = ARRLEN(joy_presets); for (int i = 0; i < num_presets; i++) { diff --git a/src/common/filesystem.c b/src/common/filesystem.c index c74991e1..133d5fae 100644 --- a/src/common/filesystem.c +++ b/src/common/filesystem.c @@ -167,8 +167,7 @@ static voidpf ZCALLBACK fopen_file_func_utf(voidpf opaque, const char *filename, if (!((filename == NULL) || (mode_fopen == NULL))) { - MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, - sizeof(wfilename) / sizeof(*wfilename)); + MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, ARRLEN(wfilename)); file = _wfopen((const wchar_t *) wfilename, mode_fopen); } @@ -1492,7 +1491,7 @@ static int Q_sort_modcmp(const void *p1, const void *p2) { static const char *first_mods[] = {BASEDIRNAME, "xatrix", "rogue", "ctf"}; - static const unsigned short int first_mods_qty = 4; + static const unsigned short int first_mods_qty = ARRLEN(first_mods); const char * s1 = * (char * const *)p1; const char * s2 = * (char * const *)p2; diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index a88e7d05..1dfc7b65 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -1104,7 +1104,7 @@ flooded(edict_t *ent) } cl = ent->client; - mx = sizeof(cl->flood_when) / sizeof(cl->flood_when[0]); + mx = ARRLEN(cl->flood_when); if (num_msgs > mx) {