summaryrefslogtreecommitdiff
path: root/accel-pppd/cli/cli.c
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2013-02-08 14:27:18 +0100
committerKozlov Dmitry <xeb@mail.ru>2013-02-12 00:05:25 +0400
commit9673dfcdd3866345c1641876b64a11c5f729f72e (patch)
treedee8b08ca57239b2ca2916136f83fb384f399be9 /accel-pppd/cli/cli.c
parent5f78642b1899c43249f3eec34bc4b60aa1b64afd (diff)
downloadaccel-ppp-9673dfcdd3866345c1641876b64a11c5f729f72e.tar.gz
accel-ppp-9673dfcdd3866345c1641876b64a11c5f729f72e.zip
cli: Improve word splitting functions
* skip_word(): ensure the for() loop won't pass over a '\0' character * split(): ensure the for() loop won't try to fill buf[MAX_CMD_ITEMS] * split(): skip leading spaces. * split(): fix exit value if no item is found (return 0 instead of 1) Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd/cli/cli.c')
-rw-r--r--accel-pppd/cli/cli.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/accel-pppd/cli/cli.c b/accel-pppd/cli/cli.c
index f6ab22d..7ed2c44 100644
--- a/accel-pppd/cli/cli.c
+++ b/accel-pppd/cli/cli.c
@@ -104,7 +104,7 @@ int __export cli_sendv(void *client, const char *fmt, ...)
static char *skip_word(char *ptr)
{
for(; *ptr; ptr++)
- if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n')
+ if (!isgraph(*ptr))
break;
return ptr;
}
@@ -119,25 +119,22 @@ static int split(char *buf, char **ptr)
{
int i;
- ptr[0] = buf;
+ buf = skip_space(buf);
+ if (!*buf)
+ return 0;
- for (i = 1; i <= MAX_CMD_ITEMS; i++) {
+ for (i = 0; i < MAX_CMD_ITEMS; i++) {
+ ptr[i] = buf;
buf = skip_word(buf);
if (!*buf)
- return i;
-
+ return i + 1;
+
*buf = 0;
-
buf = skip_space(buf + 1);
if (!*buf)
- return i;
-
- ptr[i] = buf;
+ return i + 1;
}
- buf = skip_word(buf);
- *buf = 0;
-
return i;
}