Mailing List Archive

r2960 - trunk/varnish-cache/lib/libvarnish
Author: phk
Date: 2008-07-19 13:33:24 +0200 (Sat, 19 Jul 2008)
New Revision: 2960

Modified:
trunk/varnish-cache/lib/libvarnish/num.c
Log:
FlexeLint inspired polishing:

Detect empty args.
Handle 'b' suffix in switch.



Modified: trunk/varnish-cache/lib/libvarnish/num.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/num.c 2008-07-19 10:40:13 UTC (rev 2959)
+++ trunk/varnish-cache/lib/libvarnish/num.c 2008-07-19 11:33:24 UTC (rev 2960)
@@ -45,6 +45,9 @@
double fval;
char *end;

+ if (p == NULL || *p == '\0')
+ return ("missing number");
+
fval = strtod(p, &end);
if (end == p || !isfinite(fval))
return ("Invalid number");
@@ -88,12 +91,13 @@
fval *= (uintmax_t)1 << 60;
++end;
break;
+ case 'b': case 'B':
+ ++end;
+ break;
+ default:
+ break;
}

- /* accept 'b' for 'bytes' */
- if (end[0] == 'b' || end[0] == 'B')
- ++end;
-
if (end[0] != '\0')
return ("Invalid suffix");
}