X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fvppinfra%2Funformat.c;h=3c671137941ed47cdcd79d70ab5e4ecc4ff916bd;hb=7e2cea3d26701ff1d80fda7d8ca907890e3e7baa;hp=da7622a90a823893bac0dbfbaa16cabfd73d61bd;hpb=b7b929931a07fbb27b43d5cd105f366c3e29807e;p=vpp.git diff --git a/src/vppinfra/unformat.c b/src/vppinfra/unformat.c index da7622a90a8..3c671137941 100644 --- a/src/vppinfra/unformat.c +++ b/src/vppinfra/unformat.c @@ -338,8 +338,14 @@ unformat_token (unformat_input_t * input, va_list * va) clib_memset (map, 0, sizeof (map)); for (s = token_chars; *s;) { - /* Parse range. */ - if (s[0] < s[2] && s[1] == '-') + /* + * Parse range. + * The test order is important: s[1] is valid because s[0] != '\0' but + * s[2] might not if s[1] == '\0' + * Also, if s[1] == '-' but s[2] == '\0' the test s[0] < s[2] will + * (correctly) fail + */ + if (s[1] == '-' && s[0] < s[2]) { for (i = s[0]; i <= s[2]; i++) map[i] = 1; @@ -1071,6 +1077,30 @@ unformat_init_unix_env (unformat_input_t * input, char *var) return val != 0; } +uword +unformat_data_size (unformat_input_t * input, va_list * args) +{ + u64 _a; + u64 *a = va_arg (*args, u64 *); + if (unformat (input, "%lluGb", &_a)) + *a = _a << 30; + else if (unformat (input, "%lluG", &_a)) + *a = _a << 30; + else if (unformat (input, "%lluMb", &_a)) + *a = _a << 20; + else if (unformat (input, "%lluM", &_a)) + *a = _a << 20; + else if (unformat (input, "%lluKb", &_a)) + *a = _a << 10; + else if (unformat (input, "%lluK", &_a)) + *a = _a << 10; + else if (unformat (input, "%llu", a)) + ; + else + return 0; + return 1; +} + #endif /* CLIB_UNIX */