Skip to content

Commit

Permalink
Prohibit zero channel capacity (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc authored Aug 7, 2024
1 parent 0406e2e commit 38fd099
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/zenoh-pico/api/handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ extern "C" {
\
static inline int8_t handler_new_f_name(callback_type *callback, z_owned_##handler_name##_t *handler, \
size_t capacity) { \
if (capacity < 1) { \
return _Z_ERR_INVALID; \
} \
handler->_val.collection = collection_new_f(capacity); \
if (handler->_val.collection == NULL) { \
return _Z_ERR_SYSTEM_OUT_OF_MEMORY; \
Expand Down
15 changes: 15 additions & 0 deletions tests/z_channels_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,24 @@ void sample_ring_channel_test_over_size(void) {
z_drop(z_move(handler));
}

void zero_size_test(void) {
z_owned_closure_sample_t closure;

z_owned_fifo_handler_sample_t fifo_handler;
assert(z_fifo_channel_sample_new(&closure, &fifo_handler, 0) != Z_OK);
assert(z_fifo_channel_sample_new(&closure, &fifo_handler, 1) == Z_OK);
z_drop(z_move(fifo_handler));

z_owned_ring_handler_sample_t ring_handler;
assert(z_ring_channel_sample_new(&closure, &ring_handler, 0) != Z_OK);
assert(z_ring_channel_sample_new(&closure, &ring_handler, 1) == Z_OK);
z_drop(z_move(ring_handler));
}

int main(void) {
sample_fifo_channel_test();
sample_fifo_channel_test_try_recv();
sample_ring_channel_test_in_size();
sample_ring_channel_test_over_size();
zero_size_test();
}

0 comments on commit 38fd099

Please sign in to comment.