Pi66

sta
minimal & simple status monitoring app.
git clone https://git.pi66.xyz/sta

← back to log

fix: remove and replace fmt_cmd() with snprintf

author: pi66
date: 2026-05-21 18:58
hash: dac90e210c5eb2a1c9df933fed4705052c8adbde

Diffstat:

M

sta.c
15 ++++++++----------------------
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
diff --git a/sta.c b/sta.c
index 44dbcfa..c1a1ede 100644
--- a/sta.c
+++ b/sta.c
@@ -91,20 +91,13 @@ void usage()
    exit(1);
 }

-static char *fmt_cmd(const char *cmd, char *fmt)
-{
-   char *buf = malloc(512);
-   snprintf(buf, 512, fmt, cmd);
-   return buf;
-}
-
 void append(Args *command, Pros *list)
 {
    const char *cmd = command->func(command->parm);
    if (!cmd) cmd = "N/A";
-   char *tmp = fmt_cmd(cmd, command->fmt);
+   char tmp[256];
+   snprintf(tmp, sizeof(tmp), command->fmt, cmd);
    add_pro(list, command->id, tmp);
-   free(tmp);
    show_pros(list);
 }

@@ -191,9 +184,9 @@ void run_client(int argc, char const *argv[], struct sockaddr_un *addr, int sock
            if (id == commands[i].id) {
                const char *cmd = commands[i].func(commands[i].parm);
                if (!cmd) cmd = "N/A";
-               char *tmp = fmt_cmd(cmd, commands[i].fmt);
+               char tmp[256];
+               snprintf(tmp, sizeof(tmp), commands[i].fmt, cmd);
                snprintf(buf, sizeof(buf), "%d|+|%s", id, tmp);
-               free(tmp);
                break;
            }
        }