From f5aeec7d559a3d23e65a16055732b46ed0b5fedc Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 19 Jul 2008 11:33:24 +0000 Subject: [PATCH] FlexeLint inspired polishing: Detect empty args. Handle 'b' suffix in switch. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2960 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/lib/libvarnish/num.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/varnish-cache/lib/libvarnish/num.c b/varnish-cache/lib/libvarnish/num.c index cc1ce6cc..1447173a 100644 --- a/varnish-cache/lib/libvarnish/num.c +++ b/varnish-cache/lib/libvarnish/num.c @@ -45,6 +45,9 @@ str2bytes(const char *p, uintmax_t *r, uintmax_t rel) 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,11 +91,12 @@ str2bytes(const char *p, uintmax_t *r, uintmax_t rel) fval *= (uintmax_t)1 << 60; ++end; break; - } - - /* accept 'b' for 'bytes' */ - if (end[0] == 'b' || end[0] == 'B') + case 'b': case 'B': ++end; + break; + default: + break; + } if (end[0] != '\0') return ("Invalid suffix"); -- 2.39.5