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; ssize_t len;
int parc; int parc;
char buf[READBUF_SIZE]; char buf[READBUF_SIZE];
char *parv[MAXPARA + 1]; char *parv[MAXPARA];
while((len = rb_helper_read(helper, buf, sizeof(buf))) > 0) while((len = rb_helper_read(helper, buf, sizeof(buf))) > 0)
{ {
struct authd_cb *cmd; 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]]; cmd = &authd_cmd_tab[(unsigned char)*parv[0]];
if(cmd->fn != NULL) if(cmd->fn != NULL)
{ {

View file

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

View file

@ -303,7 +303,7 @@ stats_results_callback(int resc, const char *resv[], int status, void *data)
} }
else 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); iwarn("Error getting DNS servers: %s", error);
} }
} }

View file

@ -33,8 +33,7 @@ int
msgbuf_parse(struct MsgBuf *msgbuf, char *line) msgbuf_parse(struct MsgBuf *msgbuf, char *line)
{ {
char *ch; char *ch;
char *parv[MAXPARA + 1]; char *parv[MAXPARA];
size_t n_para;
/* skip any leading spaces */ /* skip any leading spaces */
for (ch = line; *ch && *ch == ' '; ch++) for (ch = line; *ch && *ch == ' '; ch++)
@ -104,14 +103,11 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
if (*ch == '\0') if (*ch == '\0')
return 1; return 1;
n_para = rb_string_to_array(ch, parv, MAXPARA); msgbuf->n_para = rb_string_to_array(ch, (char **)msgbuf->para, MAXPARA);
if (n_para == 0) if (msgbuf->n_para == 0)
return 1; return 1;
msgbuf->cmd = parv[0]; msgbuf->cmd = msgbuf->para[0];
for (size_t i = 0; i < n_para; i++)
msgbuf_append_para(msgbuf, parv[i]);
return 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 Client *server;
struct ZipStats *zips; struct ZipStats *zips;
char *parv[7]; char *parv[6];
int parc = rb_string_to_array(ctl_buf->buf, parv, sizeof(parv) - 1); int parc = rb_string_to_array(ctl_buf->buf, parv, sizeof(parv));
if (parc < 6) if (parc < sizeof(parv))
return; return;
server = find_server(NULL, parv[1]); 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. * Changes a given buffer into an array of parameters.
* Taken from ircd-ratbox. * 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 * outputs - number of parameters
*/ */
int int
@ -92,8 +92,6 @@ rb_string_to_array(char *string, char **parv, int maxpara)
char *p, *xbuf = string; char *p, *xbuf = string;
int x = 0; int x = 0;
parv[x] = NULL;
if(string == NULL || string[0] == '\0') if(string == NULL || string[0] == '\0')
return x; return x;
@ -108,13 +106,11 @@ rb_string_to_array(char *string, char **parv, int maxpara)
{ {
xbuf++; xbuf++;
parv[x++] = xbuf; parv[x++] = xbuf;
parv[x] = NULL;
return x; return x;
} }
else else
{ {
parv[x++] = xbuf; parv[x++] = xbuf;
parv[x] = NULL;
if((p = strchr(xbuf, ' ')) != NULL) if((p = strchr(xbuf, ' ')) != NULL)
{ {
*p++ = '\0'; *p++ = '\0';
@ -134,7 +130,6 @@ rb_string_to_array(char *string, char **parv, int maxpara)
p++; p++;
parv[x++] = p; parv[x++] = p;
parv[x] = NULL;
return x; return x;
} }