X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvat2%2Fjsonconvert.c;h=645f7d4ca20c02556ed3add2985fa27a7187b783;hb=71134f26a;hp=35279eebb5f5bda390eb758e925100f91919c66f;hpb=316967cfad2860ce286ef516d608d8099de7d9a9;p=vpp.git diff --git a/src/vat2/jsonconvert.c b/src/vat2/jsonconvert.c index 35279eebb5f..645f7d4ca20 100644 --- a/src/vat2/jsonconvert.c +++ b/src/vat2/jsonconvert.c @@ -42,7 +42,8 @@ int vl_api_u8_string_fromjson(cJSON *o, u8 *s, int len) unformat_input_t input; char *p = cJSON_GetStringValue(o); unformat_init_string (&input, p, strlen(p)); - unformat(&input, "0x%U", unformat_hex_string, s); + if (!unformat (&input, "0x%U", unformat_hex_string, s)) + return -1; return 0; } @@ -59,7 +60,8 @@ u8string_fromjson(cJSON *o, char *fieldname) char *p = cJSON_GetStringValue(item); unformat_init_string (&input, p, strlen(p)); - unformat(&input, "0x%U", unformat_hex_string, &s); + if (!unformat (&input, "0x%U", unformat_hex_string, &s)) + return 0; return s; } @@ -67,7 +69,8 @@ int u8string_fromjson2(cJSON *o, char *fieldname, u8 *data) { u8 *s = u8string_fromjson(o, fieldname); - if (!s) return 0; + if (!s) + return -1; memcpy(data, s, vec_len(s)); vec_free(s); return 0; @@ -267,7 +270,8 @@ vl_api_ip4_address_t_fromjson (void **mp, int *len, cJSON *o, if (!p) return -1; unformat_init_string (&input, p, strlen(p)); - unformat(&input, "%U", unformat_ip4_address, a); + if (!unformat (&input, "%U", unformat_ip4_address, a)) + return -1; return 0; } @@ -280,7 +284,9 @@ vl_api_ip4_prefix_t_fromjson (void **mp, int *len, cJSON *o, if (!p) return -1; unformat_init_string (&input, p, strlen(p)); - unformat(&input, "%U/%d", unformat_ip4_address, &a->address, &a->len); + if (!unformat (&input, "%U/%d", unformat_ip4_address, &a->address, + &a->len)) + return -1; return 0; } @@ -299,7 +305,8 @@ vl_api_ip6_address_t_fromjson (void **mp, int *len, cJSON *o, if (!p) return -1; unformat_init_string (&input, p, strlen(p)); - unformat(&input, "%U", unformat_ip6_address, a); + if (!unformat (&input, "%U", unformat_ip6_address, a)) + return -1; return 0; } @@ -312,7 +319,8 @@ vl_api_ip6_prefix_t_fromjson (void **mp, int *len, cJSON *o, if (!p) return -1; unformat_init_string (&input, p, strlen(p)); - unformat(&input, "%U/%d", unformat_ip6_address, &a->address, &a->len); + if (!unformat (&input, "%U/%d", unformat_ip6_address, &a->address, &a->len)) + return -1; return 0; } @@ -405,7 +413,8 @@ vl_api_mac_address_t_fromjson (void **mp, int *len, cJSON *o, char *p = cJSON_GetStringValue(o); unformat_init_string (&input, p, strlen(p)); - unformat(&input, "%U", unformat_mac_address, a); + if (!unformat (&input, "%U", unformat_mac_address, a)) + return -1; return 0; } @@ -435,16 +444,6 @@ format_vl_api_interface_index_t (u8 *s, va_list *args) return format (s, "%u", *a); } -uword -unformat_vl_api_interface_index_t (unformat_input_t * input, va_list * args) -{ - u32 *a = va_arg (*args, u32 *); - - if (!unformat (input, "%u", a)) - return 0; - return 1; -} - void vl_api_string_cJSON_AddToObject(cJSON * const object, const char * const name, vl_api_string_t *astr) {