sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 484d5b434057e82275371f7fe64ef5ae6dfcb82c
parent cabbf6141e68879eb4bac39df132d0d3de43afec
Author: sin <sin@2f30.org>
Date:   Wed,  9 Oct 2013 16:28:04 +0100

Do not rely on `s' being incremented before taking the address of it

The order of evaluation for the arguments of a function is not
defined by the standard.

Diffstat:
cut.c | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/cut.c b/cut.c @@ -60,8 +60,16 @@ parselist(char *str) if(!(r = malloc(n * sizeof(Range)))) eprintf("malloc:"); for(s = str; n; n--, s++) { - r->min = (*s == '-') ? 1 : strtoul(s, &s, 10); - r->max = (*s == '-') ? strtoul(++s, &s, 10) : r->min; + if (*s == '-') + r->min = 1; + else + r->min = strtoul(s, &s, 10); + if (*s == '-') { + s++; + r->max = strtoul(s, &s, 10); + } else { + r->max = r->min; + } r->next = NULL; if(!r->min || (r->max && r->max < r->min) || (*s && *s != ',')) eprintf("cut: bad list value\n");