diff options
author | Klement Sekera <klement.sekera@gmail.com> | 2024-04-02 12:51:10 +0200 |
---|---|---|
committer | Matthew Smith <mgsmith@netgate.com> | 2024-04-05 14:03:40 +0000 |
commit | e8fb3cfe892ca1c562d63eb8854386180a297d80 (patch) | |
tree | d98966ff14eaf33cbc4166a303ff40121597700a /src/vppinfra | |
parent | 37d8c185b8902d9c69859160aee6e34ec72062fd (diff) |
api: fix [un]formatting in vpp/api/types.c
vl_api_prefix_t.len is 1 byte only, but unformat %d writes 4 bytes
add helper functions unformat_u(8|16) which don't write more than
appropriate amount of bytes
fix other similar errors in vpp/api/types.c
Type: fix
Change-Id: I74a61a377147c373f8c25ed083052b2287763c39
Signed-off-by: Klement Sekera <klement.sekera@gmail.com>
Diffstat (limited to 'src/vppinfra')
-rw-r--r-- | src/vppinfra/format.h | 6 | ||||
-rw-r--r-- | src/vppinfra/unformat.c | 25 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h index 24511735a53..a1a70a2d64f 100644 --- a/src/vppinfra/format.h +++ b/src/vppinfra/format.h @@ -276,6 +276,12 @@ unformat_init_cstring (unformat_input_t * input, char *string) /* Setup for unformat of given vector string; vector will be freed by unformat_string. */ void unformat_init_vector (unformat_input_t * input, u8 * vector_string); +/* Unformat u8 */ +unformat_function_t unformat_u8; + +/* Unformat u16 */ +unformat_function_t unformat_u16; + /* Format function for unformat input usable when an unformat error has occurred. */ u8 *format_unformat_error (u8 * s, va_list * va); diff --git a/src/vppinfra/unformat.c b/src/vppinfra/unformat.c index fe1a46e4a12..522517888c3 100644 --- a/src/vppinfra/unformat.c +++ b/src/vppinfra/unformat.c @@ -1185,6 +1185,31 @@ unformat_double_quoted_string (unformat_input_t *input, va_list *va) #endif /* CLIB_UNIX */ +__clib_export uword +unformat_u8 (unformat_input_t *input, va_list *args) +{ + u8 *d = va_arg (*args, u8 *); + + u32 tmp; + if (!unformat (input, "%u", &tmp) || tmp > CLIB_U8_MAX) + return 0; + + *d = tmp; + return 1; +} + +__clib_export uword +unformat_u16 (unformat_input_t *input, va_list *args) +{ + u16 *d = va_arg (*args, u16 *); + + u32 tmp; + if (!unformat (input, "%u", &tmp) || tmp > CLIB_U16_MAX) + return 0; + + *d = tmp; + return 1; +} /* * fd.io coding-style-patch-verification: ON |