librb: remove unnecessary NULL from the end of rb_string_to_array output

This commit is contained in:
Simon Arlott 2017-07-28 21:50:16 +01:00
parent 86432f8f86
commit 33ded5fc57
No known key found for this signature in database
GPG key ID: C8975F2043CA5D24
6 changed files with 13 additions and 22 deletions

View file

@ -275,13 +275,13 @@ parse_authd_reply(rb_helper * helper)
ssize_t len;
int parc;
char buf[READBUF_SIZE];
char *parv[MAXPARA + 1];
char *parv[MAXPARA];
while((len = rb_helper_read(helper, buf, sizeof(buf))) > 0)
{
struct authd_cb *cmd;
parc = rb_string_to_array(buf, parv, MAXPARA);
parc = rb_string_to_array(buf, parv, sizeof(parv));
cmd = &authd_cmd_tab[(unsigned char)*parv[0]];
if(cmd->fn != NULL)
{

View file

@ -400,12 +400,12 @@ static void
bandb_parse(rb_helper *helper)
{
static char buf[READBUF_SIZE];
char *parv[MAXPARA + 1];
char *parv[MAXPARA];
int len, parc;
while((len = rb_helper_read(helper, buf, sizeof(buf))))
{
parc = rb_string_to_array(buf, parv, MAXPARA);
parc = rb_string_to_array(buf, parv, sizeof(parv));
if(parc < 1)
continue;

View file

@ -303,7 +303,7 @@ stats_results_callback(int resc, const char *resv[], int status, void *data)
}
else
{
const char *error = resc ? resv[resc] : "Unknown error";
const char *error = resc ? resv[resc - 1] : "Unknown error";
iwarn("Error getting DNS servers: %s", error);
}
}

View file

@ -33,8 +33,7 @@ int
msgbuf_parse(struct MsgBuf *msgbuf, char *line)
{
char *ch;
char *parv[MAXPARA + 1];
size_t n_para;
char *parv[MAXPARA];
/* skip any leading spaces */
for (ch = line; *ch && *ch == ' '; ch++)
@ -104,14 +103,11 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
if (*ch == '\0')
return 1;
n_para = rb_string_to_array(ch, parv, MAXPARA);
if (n_para == 0)
msgbuf->n_para = rb_string_to_array(ch, (char **)msgbuf->para, MAXPARA);
if (msgbuf->n_para == 0)
return 1;
msgbuf->cmd = parv[0];
for (size_t i = 0; i < n_para; i++)
msgbuf_append_para(msgbuf, parv[i]);
msgbuf->cmd = msgbuf->para[0];
return 0;
}

View file

@ -355,10 +355,10 @@ ssl_process_zipstats(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf)
{
struct Client *server;
struct ZipStats *zips;
char *parv[7];
int parc = rb_string_to_array(ctl_buf->buf, parv, sizeof(parv) - 1);
char *parv[6];
int parc = rb_string_to_array(ctl_buf->buf, parv, sizeof(parv));
if (parc < 6)
if (parc < sizeof(parv))
return;
server = find_server(NULL, parv[1]);

View file

@ -83,7 +83,7 @@ rb_free_rb_dlink_node(rb_dlink_node *ptr)
* Changes a given buffer into an array of parameters.
* Taken from ircd-ratbox.
*
* inputs - string to parse, array to put in (size >= maxpara+1)
* inputs - string to parse, array to put in (size >= maxpara)
* outputs - number of parameters
*/
int
@ -92,8 +92,6 @@ rb_string_to_array(char *string, char **parv, int maxpara)
char *p, *xbuf = string;
int x = 0;
parv[x] = NULL;
if(string == NULL || string[0] == '\0')
return x;
@ -108,13 +106,11 @@ rb_string_to_array(char *string, char **parv, int maxpara)
{
xbuf++;
parv[x++] = xbuf;
parv[x] = NULL;
return x;
}
else
{
parv[x++] = xbuf;
parv[x] = NULL;
if((p = strchr(xbuf, ' ')) != NULL)
{
*p++ = '\0';
@ -134,7 +130,6 @@ rb_string_to_array(char *string, char **parv, int maxpara)
p++;
parv[x++] = p;
parv[x] = NULL;
return x;
}