[hackers] [sbase] Do not rely on `s' being incremented before taking the address of it || sin

From: <git_AT_suckless.org>
Date: Wed, 09 Oct 2013 17:44:08 +0200

commit 484d5b434057e82275371f7fe64ef5ae6dfcb82c
Author: sin <sin_AT_2f30.org>
Date: Wed Oct 9 16:28:04 2013 +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.

diff --git a/cut.c b/cut.c
index 72c20bc..40dc250 100644
--- a/cut.c
+++ b/cut.c
_AT_@ -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
");
Received on Wed Oct 09 2013 - 17:44:08 CEST

This archive was generated by hypermail 2.3.0 : Wed Oct 09 2013 - 17:48:35 CEST