From ed34bceafdb4f1d1d3bcb9ccc58c9c8c936ee3dd Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Thu, 18 Jan 2024 14:08:41 +0100 Subject: [PATCH] z_bytes: expose wrap and rename new to from_str --- include/zenoh-pico/api/primitives.h | 2 ++ include/zenoh-pico/api/types.h | 4 ++-- src/api/api.c | 4 +--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index afed6e13f..badb5b7e9 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -32,6 +32,8 @@ extern "C" { #endif /********* Data Types Handlers *********/ +#define z_bytes_wrap _z_bytes_wrap + /** * Constructs a :c:type:`z_string_t` departing from a ``const char *``. * It is a loaned key expression that aliases ``value``. diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index 6b1d176ab..be3726d04 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -656,11 +656,11 @@ z_owned_bytes_map_t z_bytes_map_null(void); #endif /** - * Returns a view of `str` using `strlen`. + * Returns a view of `str` using `strlen` (this constructor should not be used on untrusted input). * * `str == NULL` will cause this to return `z_bytes_null()` */ -z_bytes_t z_bytes_new(const char *str); +z_bytes_t z_bytes_from_str(const char *str); /** * Returns the gravestone value for `z_bytes_t` */ diff --git a/src/api/api.c b/src/api/api.c index 0bd2c016b..432fd0855 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -1270,8 +1270,6 @@ int8_t z_bytes_map_iter(const z_owned_bytes_map_t *this_, z_attachment_iter_body } z_owned_bytes_map_t z_bytes_map_new(void) { return (z_owned_bytes_map_t){._inner = _z_bytes_pair_list_new()}; } z_owned_bytes_map_t z_bytes_map_null(void) { return (z_owned_bytes_map_t){._inner = NULL}; } -z_bytes_t z_bytes_new(const char *str) { - return (z_bytes_t){.len = strlen(str), ._is_alloc = false, .start = (unsigned char *)str}; -} +z_bytes_t z_bytes_from_str(const char *str) { return z_bytes_wrap((const uint8_t *)str, strlen(str)); } z_bytes_t z_bytes_null(void) { return (z_bytes_t){.len = 0, ._is_alloc = false, .start = NULL}; } #endif \ No newline at end of file