From 8a02a1946aa8dbedbf44a5de00e849b1e06363d7 Mon Sep 17 00:00:00 2001 From: Tim Cava Date: Sun, 7 Jul 2013 08:39:34 +0000 Subject: [PATCH] Simplify show_scores() by sending each line immediately, rather than buffering lines together. This also avoids a dereference before null check found by Coverity. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@255 13b04d17-f746-0410-82c6-800466cd88b0 --- dll/acro/acro.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/dll/acro/acro.c b/dll/acro/acro.c index 28a9e18..436fbc3 100644 --- a/dll/acro/acro.c +++ b/dll/acro/acro.c @@ -513,59 +513,42 @@ void show_acros(prec *players, char *chan) void show_scores(grec *acro, srec *score, srec *gscore, char *chan) { - char *line, buff[201]; int i; - line = (char *)new_malloc(513); - memset(buff, 0, sizeof(buff)); if (score) score = sort_scores(score); if (gscore && (acro->round >= acro->rounds)) gscore = sort_scores(gscore); if (acro->round < acro->rounds) - sprintf(line, "PRIVMSG %s :Scores for round %d\r\nPRIVMSG %s :Nick Score\r\nPRIVMSG %s :-----------------\r\n", chan, acro->round, chan, chan); + send_to_server("PRIVMSG %s :Scores for round %d\r\nPRIVMSG %s :Nick Score\r\nPRIVMSG %s :-----------------", chan, acro->round, chan, chan); else - sprintf(line, "PRIVMSG %s :Game over, tallying final scores...\r\nPRIVMSG %s : Game Score Overall Score\r\nPRIVMSG %s :Nick Score Nick Score\r\nPRIVMSG %s :----------------- -----------------\r\n", chan, chan, chan, chan); + send_to_server("PRIVMSG %s :Game over, tallying final scores...\r\nPRIVMSG %s : Game Score Overall Score\r\nPRIVMSG %s :Nick Score Nick Score\r\nPRIVMSG %s :----------------- -----------------", chan, chan, chan, chan); for (i = 0; i < acro->top && (score || gscore); i++) { if ((acro->round < acro->rounds) && score) { - snprintf(buff, 198, "PRIVMSG %s :%-9s %lu", chan, score->nick, score->score); - strcat(buff, "\r\n"); + send_to_server("PRIVMSG %s :%-9s %lu", chan, score->nick, score->score); score = score->next; } else if (acro->round == acro->rounds && (score || gscore)) { if (!score && gscore) { - snprintf(buff, 198, "PRIVMSG %s : %-9s %lu", chan, gscore->nick, gscore->score); - strcat(buff, "\r\n"); + send_to_server("PRIVMSG %s : %-9s %lu", chan, gscore->nick, gscore->score); gscore = gscore->next; } else if (score && !gscore) { - snprintf(buff, 198, "PRIVMSG %s :%-9s %lu", chan, score->nick, score->score); - strcat(buff, "\r\n"); + send_to_server("PRIVMSG %s :%-9s %lu", chan, score->nick, score->score); score = score->next; } else if (gscore && score) { - snprintf(buff, 198, "PRIVMSG %s :%-9s %-5lu %-9s %lu", chan, score->nick, score->score, gscore->nick, gscore->score); - strcat(buff, "\r\n"); + send_to_server("PRIVMSG %s :%-9s %-5lu %-9s %lu", chan, score->nick, score->score, gscore->nick, gscore->score); gscore = gscore->next; score = score->next; } } - if (strlen(line)+strlen(buff) >= 512) - { - send_to_server("%s", line); - memset(line, 0, 513); - } - strcat(line, buff); - memset(buff, 0, sizeof(buff)); } - if (line) - send_to_server("%s", line); - new_free(&line); } void free_round(prec **players, vrec **voters)