From 0e3529e3b5c6c2383226f271e51ab50d990b0a1b Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 6 Jul 2024 19:04:01 +0200 Subject: Added a new type and replaced sprintf() calls with msnprintf() --- FICS/command.h | 4 ++++ FICS/ficsmain.c | 6 +++--- FICS/network.c | 19 +++++++++++-------- FICS/network.h | 4 ++-- 4 files changed, 20 insertions(+), 13 deletions(-) (limited to 'FICS') diff --git a/FICS/command.h b/FICS/command.h index 1f2eeef..f7ca75f 100644 --- a/FICS/command.h +++ b/FICS/command.h @@ -95,6 +95,10 @@ typedef struct s_alias_type { char *alias; } alias_type; +typedef struct { + char com[MAX_STRING_LENGTH]; +} comstr_t; + extern char *adhelp_dir; extern char *adj_dir; extern char *board_dir; diff --git a/FICS/ficsmain.c b/FICS/ficsmain.c index 71c11b4..e9a2783 100644 --- a/FICS/ficsmain.c +++ b/FICS/ficsmain.c @@ -111,11 +111,11 @@ TerminateServer(int sig) PRIVATE void main_event_loop(void) { - char command_string[MAX_STRING_LENGTH]; - int sockfd = -1; + comstr_t str; + int sockfd = -1; while (1) { - ngc2(command_string, HEARTBEATTIME); + ngc2(&str, HEARTBEATTIME); if (process_heartbeat(&sockfd) == COM_LOGOUT && sockfd != -1) { process_disconnection(sockfd); diff --git a/FICS/network.c b/FICS/network.c index 29c0041..41db477 100644 --- a/FICS/network.c +++ b/FICS/network.c @@ -15,6 +15,7 @@ #include "common.h" #include "config.h" #include "ficsmain.h" +#include "maxxes-utils.h" #include "network.h" #include "playerdb.h" #include "rmalloc.h" @@ -328,7 +329,7 @@ net_send_string(int fd, char *str, int format) * C) if some error, return -1. */ PUBLIC int -readline2(char *com, int who) +readline2(comstr_t *cs, int who) { int howmany, state, fd, pending; unsigned char *start, *s, *d; @@ -378,7 +379,8 @@ readline2(char *com, int who) state = 1; } else if (*s == '\n') { *s = '\0'; - sprintf(com, "%s", start); + msnprintf(cs->com, ARRAY_SIZE(cs->com), "%s", + start); if (howmany) bcopy(s + 1, start, howmany); con[who].state = 0; @@ -416,7 +418,8 @@ readline2(char *com, int who) state = 1; else if (*s == '\n') { *d = '\0'; - sprintf(com, "%s", start); + msnprintf(cs->com, ARRAY_SIZE(cs->com), "%s", + start); if (howmany) memmove(start, s + 1, howmany); con[who].state = 0; @@ -454,7 +457,7 @@ readline2(char *com, int who) if (con[who].numPending == MAX_STRING_LENGTH - 1) { // buffer full *d = '\0'; - sprintf(com, "%s", start); + msnprintf(cs->com, ARRAY_SIZE(cs->com), "%s", start); con[who].state = 0; con[who].numPending = 0; con[who].processed = 0; @@ -574,7 +577,7 @@ net_connected_host(int fd) } PUBLIC void -ngc2(char *com, int timeout) +ngc2(comstr_t *cs, int timeout) { fd_set readfds; int fd, loop, nfound, lineComplete; @@ -617,17 +620,17 @@ ngc2(char *com, int timeout) if (con[loop].status != NETSTAT_EMPTY) { fd = con[loop].fd; - if ((lineComplete = readline2(com, fd)) == 0) { + if ((lineComplete = readline2(cs, fd)) == 0) { // partial line: do nothing continue; } if (lineComplete > 0) { // complete line: process it #ifdef TIMESEAL - if (!parseInput(com, &con[loop])) + if (!parseInput(cs->com, &con[loop])) continue; #endif - if (process_input(fd, com) != COM_LOGOUT) { + if (process_input(fd, cs->com) != COM_LOGOUT) { net_flush_connection(fd); continue; } diff --git a/FICS/network.h b/FICS/network.h index 9aaf067..2225734 100644 --- a/FICS/network.h +++ b/FICS/network.h @@ -85,12 +85,12 @@ extern int net_addConnection(int, unsigned int); extern int net_consize(void); extern int net_init(int); extern int net_send_string(int, char *, int); -extern int readline2(char *, int); +extern int readline2(comstr_t *, int); extern unsigned int net_connected_host(int); extern void net_close(void); extern void net_close_connection(int); -extern void ngc2(char *, int); +extern void ngc2(comstr_t *, int); extern void turn_echo_off(int); extern void turn_echo_on(int); #endif /* _NETWORK_H */ -- cgit v1.2.3