have strtochan return zero if the depth is invalid. Notes: Wed May 31 10:00:28 EDT 2006 rsc please resubmit this with d and c out of the for loop initialization. since they're not part of the rest of the for(;;) expressions, they don't belong there. just use a normal initialization and leave the loop as a while loop. thanks. Reference: /n/sources/patch/sorry/strtochan Date: Sun May 28 23:29:38 CES 2006 Signed-off-by: quanstro@quanstro.net Reviewed-by: rsc --- /sys/src/libdraw/chan.c Sun May 28 23:27:23 2006 +++ /sys/src/libdraw/chan.c Sun May 28 23:27:20 2006 @@ -41,23 +41,25 @@ { char *p, *q; ulong c; - int t, n; + int t, n, d; - c = 0; p=s; while(*p && isspace(*p)) p++; - while(*p && !isspace(*p)){ + for(d = 0, c = 0; *p && !isspace(*p);){ if((q = strchr(channames, p[0])) == nil) return 0; t = q-channames; if(p[1] < '0' || p[1] > '9') return 0; n = p[1]-'0'; + d += n; c = (c<<8) | __DC(t, n); p += 2; } + if(d==0 || (d>8 && d%8) || (d<8 && 8%d)) + return 0; return c; }