From d54381f00991669fa4ee4f3a8037f246ca1904f8 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sat, 12 Apr 2014 20:16:33 +0300 Subject: Fix out of bound access, and provide better tokenize api. --- lib/util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/util.c') diff --git a/lib/util.c b/lib/util.c index c4533ca..bcb27cb 100644 --- a/lib/util.c +++ b/lib/util.c @@ -34,11 +34,16 @@ char* _bmStrdup(const char *string) * Replaces next token in string with '\0' and returns position for the replaced token. * * @param string C "string" where token will be replaced. + * @param outNext Reference to position of next delimiter, or 0 if none. * @return Position of the replaced token. */ -size_t _bmStripToken(char *string, const char *token) +size_t _bmStripToken(char *string, const char *token, size_t *outNext) { size_t len = strcspn(string, token); + + if (outNext) + *outNext = len + (string[len] != 0); + string[len] = 0; return len; } -- cgit v1.2.3-70-g09d2