- for (i=0; i<4 && *s; i++) {
- a[i] = x = strtoul(s, (char **)&z, 10);
- if (!isdigit(*s) || z==s || (*z && *z != '.') || x>255)
- return 0;
- s=z+1;
+ for (i=0; i<4; i++) {
+ for (v=j=0; j<3 && isdigit(s[j]); j++)
+ v = 10*v + s[j]-'0';
+ if (j==0 || (j>1 && s[0]=='0') || v>255) return 0;
+ a[i] = v;
+ if (s[j]==0 && i==3) return 1;
+ if (s[j]!='.') return 0;
+ s += j+1;