]> err.no Git - varnish/commitdiff
FlexeLint inspired polishing:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Jul 2008 11:33:24 +0000 (11:33 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Jul 2008 11:33:24 +0000 (11:33 +0000)
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

index cc1ce6cc61af29f539c540d98aa0e38cff0b6d45..1447173af6763b5a93933103a00a32ad61d57514 100644 (file)
@@ -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");