From 1894a200e2946bb86b6b6f792a7c52dcf199873b Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 1 Apr 2024 18:54:27 +0200 Subject: Reformatted set_busy() and replaced the sprintf() call --- FICS/variable.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'FICS') diff --git a/FICS/variable.c b/FICS/variable.c index d2e2d69..777d3e3 100644 --- a/FICS/variable.c +++ b/FICS/variable.c @@ -43,6 +43,10 @@ #include "utils.h" #include "variable.h" +#if __linux__ +#include +#endif + PRIVATE int set_boolean_var(int *var, char *val) { int v = -1; @@ -585,22 +589,27 @@ PRIVATE int set_partner(int p, char *var, char *val) return VAR_OK; } -PRIVATE int set_busy(int p, char *var, char *val) +PRIVATE int +set_busy(int p, char *var, char *val) { - if (!val) { - parray[p].busy[0] = '\0'; - pprintf(p, "Your \"busy\" string was cleared.\n"); - return VAR_OK; - } - if ((val) && (!printablestring(val))) - return VAR_BADVAL; - if (strlen(val) > 50) { - pprintf(p, "That string is too long.\n"); - return VAR_BADVAL; - } - sprintf(parray[p].busy, "%s", val); - pprintf(p, "Your \"busy\" string was set to \" %s\"\n", parray[p].busy); - return VAR_OK; + if (!val) { + parray[p].busy[0] = '\0'; + pprintf(p, "Your \"busy\" string was cleared.\n"); + return VAR_OK; + } + + if (val && !printablestring(val)) + return VAR_BADVAL; + + if (strlen(val) > 50) { + pprintf(p, "That string is too long.\n"); + return VAR_BADVAL; + } + + strlcpy(parray[p].busy, val, sizeof(parray[p].busy)); + + pprintf(p, "Your \"busy\" string was set to \" %s\"\n", parray[p].busy); + return VAR_OK; } PRIVATE int -- cgit v1.2.3