diff options
author | Ole Troan <ot@cisco.com> | 2021-02-16 00:31:52 +0100 |
---|---|---|
committer | Neale Ranns <neale@graphiant.com> | 2021-02-16 08:13:41 +0000 |
commit | 316967cfad2860ce286ef516d608d8099de7d9a9 (patch) | |
tree | 48c1146a0b2f445f8a55ef16812e14ecbebe88ee /src/vat2 | |
parent | 810bb89bdd454a96e12183c2b18a43c729aa5b57 (diff) |
vppapigen: fix coverity issues in jsonconvert
Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: I92e03a5a3fcbdab6ce4d178193dceb4450ac0f62
Diffstat (limited to 'src/vat2')
-rw-r--r-- | src/vat2/jsonconvert.c | 74 | ||||
-rw-r--r-- | src/vat2/jsonconvert.h | 69 | ||||
-rw-r--r-- | src/vat2/test/vat2_test.api | 4 | ||||
-rw-r--r-- | src/vat2/test/vat2_test.c | 7 |
4 files changed, 101 insertions, 53 deletions
diff --git a/src/vat2/jsonconvert.c b/src/vat2/jsonconvert.c index ec066287035..35279eebb5f 100644 --- a/src/vat2/jsonconvert.c +++ b/src/vat2/jsonconvert.c @@ -258,78 +258,98 @@ format_ip6_address (u8 * s, va_list * args) return s; } -void *vl_api_ip4_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip4_address_t *a) +int +vl_api_ip4_address_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip4_address_t *a) { unformat_input_t input; char *p = cJSON_GetStringValue(o); - if (!p) return 0; + if (!p) + return -1; unformat_init_string (&input, p, strlen(p)); unformat(&input, "%U", unformat_ip4_address, a); - return mp; + return 0; } -void *vl_api_ip4_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip4_prefix_t *a) +int +vl_api_ip4_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip4_prefix_t *a) { unformat_input_t input; char *p = cJSON_GetStringValue(o); - if (!p) return 0; + if (!p) + return -1; unformat_init_string (&input, p, strlen(p)); unformat(&input, "%U/%d", unformat_ip4_address, &a->address, &a->len); - return mp; + return 0; } -void *vl_api_ip4_address_with_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip4_prefix_t *a) +int +vl_api_ip4_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip4_prefix_t *a) { return vl_api_ip4_prefix_t_fromjson(mp, len, o, a); } -void *vl_api_ip6_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip6_address_t *a) +int +vl_api_ip6_address_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip6_address_t *a) { unformat_input_t input; char *p = cJSON_GetStringValue(o); - if (!p) return 0; + if (!p) + return -1; unformat_init_string (&input, p, strlen(p)); unformat(&input, "%U", unformat_ip6_address, a); - return mp; + return 0; } -void *vl_api_ip6_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip6_prefix_t *a) +int +vl_api_ip6_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip6_prefix_t *a) { unformat_input_t input; char *p = cJSON_GetStringValue(o); - if (!p) return 0; + if (!p) + return -1; unformat_init_string (&input, p, strlen(p)); unformat(&input, "%U/%d", unformat_ip6_address, &a->address, &a->len); - return mp; + return 0; } -void *vl_api_ip6_address_with_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip6_prefix_t *a) +int +vl_api_ip6_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip6_prefix_t *a) { return vl_api_ip6_prefix_t_fromjson(mp, len, o, a); } -void *vl_api_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_address_t *a) +int +vl_api_address_t_fromjson (void **mp, int *len, cJSON *o, vl_api_address_t *a) { unformat_input_t input; char *p = cJSON_GetStringValue(o); - if (!p) return 0; + if (!p) + return -1; unformat_init_string (&input, p, strlen(p)); if (unformat (&input, "%U", unformat_ip4_address, &a->un.ip4)) a->af = ADDRESS_IP4; else if (unformat (&input, "%U", unformat_ip6_address, &a->un.ip6)) a->af = ADDRESS_IP6; else - return (0); - return mp; + return -1; + return 0; } -void *vl_api_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_prefix_t *a) +int +vl_api_prefix_t_fromjson (void **mp, int *len, cJSON *o, vl_api_prefix_t *a) { unformat_input_t input; char *p = cJSON_GetStringValue(o); - if (!p) return 0; + if (!p) + return -1; unformat_init_string (&input, p, strlen(p)); int plen; if (unformat (&input, "%U/%d", unformat_ip4_address, &a->address.un.ip4, &plen)) @@ -337,12 +357,14 @@ void *vl_api_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_prefix_t *a) else if (unformat (&input, "%U/%d", unformat_ip6_address, &a->address.un.ip6, &plen)) a->address.af = ADDRESS_IP6; else - return (0); + return -1; a->len = plen; - return mp; + return 0; } -void *vl_api_address_with_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_prefix_t *a) +int +vl_api_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_prefix_t *a) { return vl_api_prefix_t_fromjson(mp, len, o, a); } @@ -375,14 +397,16 @@ unformat_mac_address (unformat_input_t * input, va_list * args) return (0); } -void *vl_api_mac_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_mac_address_t *a) +int +vl_api_mac_address_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_mac_address_t *a) { unformat_input_t input; char *p = cJSON_GetStringValue(o); unformat_init_string (&input, p, strlen(p)); unformat(&input, "%U", unformat_mac_address, a); - return mp; + return 0; } /* Format an IP4 address. */ diff --git a/src/vat2/jsonconvert.h b/src/vat2/jsonconvert.h index 2e723fa637d..ee1355f1f37 100644 --- a/src/vat2/jsonconvert.h +++ b/src/vat2/jsonconvert.h @@ -39,37 +39,50 @@ #undef _ int vl_api_bool_fromjson(cJSON *o, bool *d); -void *vl_api_ip4_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip4_address_t *a); -void *vl_api_ip4_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip4_prefix_t *a); -void *vl_api_ip4_address_with_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip4_prefix_t *a); -void *vl_api_ip6_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip6_address_t *a); -void *vl_api_ip6_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip6_prefix_t *a); -void *vl_api_ip6_address_with_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_ip6_prefix_t *a); -void *vl_api_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_address_t *a); -void *vl_api_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_prefix_t *a); -void *vl_api_address_with_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_prefix_t *a); -void *vl_api_mac_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_mac_address_t *a); + int vl_api_ip4_address_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip4_address_t *a); + int vl_api_ip4_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip4_prefix_t *a); + int vl_api_ip4_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip4_prefix_t *a); + int vl_api_ip6_address_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip6_address_t *a); + int vl_api_ip6_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip6_prefix_t *a); + int vl_api_ip6_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_ip6_prefix_t *a); + int vl_api_address_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_address_t *a); + int vl_api_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_prefix_t *a); + int vl_api_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_prefix_t *a); + int vl_api_mac_address_t_fromjson (void **mp, int *len, cJSON *o, + vl_api_mac_address_t *a); -uword unformat_ip4_address(unformat_input_t * input, va_list * args); -uword unformat_ip6_address(unformat_input_t * input, va_list * args); -u8 *format_ip6_address(u8 * s, va_list * args); -uword unformat_mac_address(unformat_input_t * input, va_list * args); -u8 *format_ip4_address(u8 * s, va_list * args); -u8 *format_vl_api_interface_index_t(u8 *s, va_list *args); -uword unformat_vl_api_interface_index_t(unformat_input_t * input, va_list * args); -u8 *format_vl_api_timestamp_t(u8 * s, va_list * args); -u8 *format_vl_api_timedelta_t(u8 * s, va_list * args); -uword unformat_vl_api_timedelta_t(unformat_input_t * input, va_list * args); -uword unformat_vl_api_timestamp_t(unformat_input_t * input, va_list * args); -u8 *format_vl_api_gbp_scope_t(u8 * s, va_list * args); -uword unformat_vl_api_gbp_scope_t(unformat_input_t * input, va_list * args); + uword unformat_ip4_address (unformat_input_t *input, va_list *args); + uword unformat_ip6_address (unformat_input_t *input, va_list *args); + u8 *format_ip6_address (u8 *s, va_list *args); + uword unformat_mac_address (unformat_input_t *input, va_list *args); + u8 *format_ip4_address (u8 *s, va_list *args); + u8 *format_vl_api_interface_index_t (u8 *s, va_list *args); + uword unformat_vl_api_interface_index_t (unformat_input_t *input, + va_list *args); + u8 *format_vl_api_timestamp_t (u8 *s, va_list *args); + u8 *format_vl_api_timedelta_t (u8 *s, va_list *args); + uword unformat_vl_api_timedelta_t (unformat_input_t *input, va_list *args); + uword unformat_vl_api_timestamp_t (unformat_input_t *input, va_list *args); + u8 *format_vl_api_gbp_scope_t (u8 *s, va_list *args); + uword unformat_vl_api_gbp_scope_t (unformat_input_t *input, va_list *args); -int vl_api_c_string_to_api_string(const char *buf, vl_api_string_t * str); -void vl_api_string_cJSON_AddToObject(cJSON * const object, const char * const name, vl_api_string_t *astr); + int vl_api_c_string_to_api_string (const char *buf, vl_api_string_t *str); + void vl_api_string_cJSON_AddToObject (cJSON *const object, + const char *const name, + vl_api_string_t *astr); -u8 *u8string_fromjson(cJSON *o, char *fieldname); -int u8string_fromjson2(cJSON *o, char *fieldname, u8 *data); -int vl_api_u8_string_fromjson(cJSON *o, u8 *s, int len); + u8 *u8string_fromjson (cJSON *o, char *fieldname); + int u8string_fromjson2 (cJSON *o, char *fieldname, u8 *data); + int vl_api_u8_string_fromjson (cJSON *o, u8 *s, int len); #define foreach_vat2_tojson \ _(ip4_address) \ diff --git a/src/vat2/test/vat2_test.api b/src/vat2/test/vat2_test.api index ff503f0d03a..58961475e30 100644 --- a/src/vat2/test/vat2_test.api +++ b/src/vat2/test/vat2_test.api @@ -77,3 +77,7 @@ autoreply define test_vla5 { vl_api_test_vlatype3_t data; }; +/* Addresses */ +autoreply define test_addresses { + vl_api_address_t a; +}; diff --git a/src/vat2/test/vat2_test.c b/src/vat2/test/vat2_test.c index 10cfee4be17..f28bb414d56 100644 --- a/src/vat2/test/vat2_test.c +++ b/src/vat2/test/vat2_test.c @@ -142,6 +142,11 @@ struct msgs msgs[] = { .tojson = (tojson_fn_t) vl_api_test_vla5_t_tojson, .fromjson = (fromjson_fn_t) vl_api_test_vla5_t_fromjson, }, + { + .name = "test_addresses", + .tojson = (tojson_fn_t) vl_api_test_addresses_t_tojson, + .fromjson = (fromjson_fn_t) vl_api_test_addresses_t_fromjson, + }, }; struct tests tests[] = { @@ -163,6 +168,8 @@ struct tests tests[] = { "[1,2,3,4,5] }}" }, { .s = "{\"_msgname\": \"test_vla5\", \"data\": { \"count\": 5, \"vla\": " "\"0xaabbccddee\" }}" }, + { .s = "{\"_msgname\": \"test_addresses\", \"a\": \"1.2.3.4\" }" }, + { .s = "{\"_msgname\": \"test_addresses\", \"a\": \"2001:db8::23\" }" }, }; int main (int argc, char **argv) |