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
This commit is contained in:
@@ -513,59 +513,42 @@ void show_acros(prec *players, char *chan)
|
|||||||
|
|
||||||
void show_scores(grec *acro, srec *score, srec *gscore, char *chan)
|
void show_scores(grec *acro, srec *score, srec *gscore, char *chan)
|
||||||
{
|
{
|
||||||
char *line, buff[201];
|
|
||||||
int i;
|
int i;
|
||||||
line = (char *)new_malloc(513);
|
|
||||||
memset(buff, 0, sizeof(buff));
|
|
||||||
if (score)
|
if (score)
|
||||||
score = sort_scores(score);
|
score = sort_scores(score);
|
||||||
if (gscore && (acro->round >= acro->rounds))
|
if (gscore && (acro->round >= acro->rounds))
|
||||||
gscore = sort_scores(gscore);
|
gscore = sort_scores(gscore);
|
||||||
if (acro->round < acro->rounds)
|
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
|
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++)
|
for (i = 0; i < acro->top && (score || gscore); i++)
|
||||||
{
|
{
|
||||||
if ((acro->round < acro->rounds) && score)
|
if ((acro->round < acro->rounds) && score)
|
||||||
{
|
{
|
||||||
snprintf(buff, 198, "PRIVMSG %s :%-9s %lu", chan, score->nick, score->score);
|
send_to_server("PRIVMSG %s :%-9s %lu", chan, score->nick, score->score);
|
||||||
strcat(buff, "\r\n");
|
|
||||||
score = score->next;
|
score = score->next;
|
||||||
}
|
}
|
||||||
else if (acro->round == acro->rounds && (score || gscore))
|
else if (acro->round == acro->rounds && (score || gscore))
|
||||||
{
|
{
|
||||||
if (!score && gscore)
|
if (!score && gscore)
|
||||||
{
|
{
|
||||||
snprintf(buff, 198, "PRIVMSG %s : %-9s %lu", chan, gscore->nick, gscore->score);
|
send_to_server("PRIVMSG %s : %-9s %lu", chan, gscore->nick, gscore->score);
|
||||||
strcat(buff, "\r\n");
|
|
||||||
gscore = gscore->next;
|
gscore = gscore->next;
|
||||||
}
|
}
|
||||||
else if (score && !gscore)
|
else if (score && !gscore)
|
||||||
{
|
{
|
||||||
snprintf(buff, 198, "PRIVMSG %s :%-9s %lu", chan, score->nick, score->score);
|
send_to_server("PRIVMSG %s :%-9s %lu", chan, score->nick, score->score);
|
||||||
strcat(buff, "\r\n");
|
|
||||||
score = score->next;
|
score = score->next;
|
||||||
}
|
}
|
||||||
else if (gscore && score)
|
else if (gscore && score)
|
||||||
{
|
{
|
||||||
snprintf(buff, 198, "PRIVMSG %s :%-9s %-5lu %-9s %lu", chan, score->nick, score->score, gscore->nick, gscore->score);
|
send_to_server("PRIVMSG %s :%-9s %-5lu %-9s %lu", chan, score->nick, score->score, gscore->nick, gscore->score);
|
||||||
strcat(buff, "\r\n");
|
|
||||||
gscore = gscore->next;
|
gscore = gscore->next;
|
||||||
score = score->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)
|
void free_round(prec **players, vrec **voters)
|
||||||
|
|||||||
Reference in New Issue
Block a user