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.
This commit is contained in:
sin 2013-10-09 16:28:04 +01:00
parent cabbf6141e
commit 484d5b4340

12
cut.c
View File

@ -60,8 +60,16 @@ parselist(char *str)
if(!(r = malloc(n * sizeof(Range)))) if(!(r = malloc(n * sizeof(Range))))
eprintf("malloc:"); eprintf("malloc:");
for(s = str; n; n--, s++) { for(s = str; n; n--, s++) {
r->min = (*s == '-') ? 1 : strtoul(s, &s, 10); if (*s == '-')
r->max = (*s == '-') ? strtoul(++s, &s, 10) : r->min; 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; r->next = NULL;
if(!r->min || (r->max && r->max < r->min) || (*s && *s != ',')) if(!r->min || (r->max && r->max < r->min) || (*s && *s != ','))
eprintf("cut: bad list value\n"); eprintf("cut: bad list value\n");