From c58f0bac7ec3441b0878f6bda1f5218c5f06ea6f Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Wed, 23 Jan 2013 21:34:35 +0000 Subject: [PATCH] Get rid of the sole strtok call in the tree. It might have (not here, though) side effects, since it isn't reentrant. Considering that it always has to span five characters (color), use strspn to simplify the code and save a few lines. --- paint.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/paint.c b/paint.c index e0b4a8f..17a8ad4 100644 --- a/paint.c +++ b/paint.c @@ -683,24 +683,13 @@ paint_str2color(const char *str) { if (strncasecmp(str, "color", 5) == 0) { const char *errstr; - char *color; - char *numberstr; - int number; + int number; - if ((color = strdup(str)) == NULL) - err(1, "%s: strdup of '%s' failed.", __FUNCTION__, str); - - if ((numberstr = strtok(color, "color")) == NULL) { - free(color); - return -2; - } - number = (int)strtonum(numberstr, -1, 255, &errstr); - if (errstr != NULL) { - free(color); + str += strspn(str, "color"); + number = (int)strtonum(str, -1, 255, &errstr); + if (errstr != NULL) return -2; - } - free(color); return number; } else if (strcasecmp(str, "black") == 0)