diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2014-04-12 20:16:33 +0300 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2014-04-12 20:16:33 +0300 |
commit | d54381f00991669fa4ee4f3a8037f246ca1904f8 (patch) | |
tree | 6356280933b745b1598617b296b6a701f73939f5 /lib/util.c | |
parent | e738ae17728c697d64beb9adb2dfcc921f864120 (diff) | |
download | bemenu-d54381f00991669fa4ee4f3a8037f246ca1904f8.tar.gz bemenu-d54381f00991669fa4ee4f3a8037f246ca1904f8.tar.bz2 bemenu-d54381f00991669fa4ee4f3a8037f246ca1904f8.zip |
Fix out of bound access, and provide better tokenize api.
Diffstat (limited to 'lib/util.c')
-rw-r--r-- | lib/util.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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; } |