1
0
forked from bip/bip

snprintf fixups.

This commit is contained in:
Arnaud Cornet 2007-11-25 18:35:53 +01:00
parent 05e0f84af8
commit 7020e7fa4c

View File

@ -1774,14 +1774,15 @@ void set_on_connect_send(struct link_client *ic, char *val)
s = list_remove_last(&link->on_connect_send); s = list_remove_last(&link->on_connect_send);
if (s) if (s)
free(s); free(s);
bip_notify(ic, "on_connect_send cleared."); bip_notify(ic, "last on_connect_send string deleted.");
} }
} }
#define ON_CONNECT_MAX_STRSIZE 1024
void adm_on_connect_send(struct link_client *ic, struct line *line, void adm_on_connect_send(struct link_client *ic, struct line *line,
unsigned int privmsg) unsigned int privmsg)
{ {
char buf[4096]; char buf[ON_CONNECT_MAX_STRSIZE];
int t_wrote = 0; int t_wrote = 0;
unsigned int i; unsigned int i;
@ -1794,14 +1795,26 @@ void adm_on_connect_send(struct link_client *ic, struct line *line,
return; return;
for (i = privmsg + 2; i < line->elemc; i++) { for (i = privmsg + 2; i < line->elemc; i++) {
if (t_wrote) if (t_wrote) {
t_wrote += snprintf(buf, 4095 - t_wrote, " %s", t_wrote += snprintf(buf,
line->elemv[i]); ON_CONNECT_MAX_STRSIZE - 1 - t_wrote,
else " %s", line->elemv[i]);
t_wrote = snprintf(buf, 4095, "%s", line->elemv[i]); if (t_wrote >= ON_CONNECT_MAX_STRSIZE)
goto noroom;
} else {
t_wrote = snprintf(buf, ON_CONNECT_MAX_STRSIZE - 1,
"%s", line->elemv[i]);
if (t_wrote >= ON_CONNECT_MAX_STRSIZE)
goto noroom;
}
} }
buf[4095] = 0; ok:
buf[ON_CONNECT_MAX_STRSIZE - 1] = 0;
set_on_connect_send(ic, buf); set_on_connect_send(ic, buf);
return;
noroom:
bip_notify(ic, "on connect send string too big, truncated");
goto ok;
} }
void adm_away_nick(struct link_client *ic, char *val) void adm_away_nick(struct link_client *ic, char *val)