From e9c21932a94df3ee112c9d4676650606373b1a7d Mon Sep 17 00:00:00 2001 From: Christian von Elm Date: Tue, 22 Oct 2024 13:46:36 +0200 Subject: [PATCH] address requested changes --- include/lo2s/ringbuf.hpp | 15 +++++++++++++++ src/monitor/process_monitor_main.cpp | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/lo2s/ringbuf.hpp b/include/lo2s/ringbuf.hpp index e918e58f..60fe592b 100644 --- a/include/lo2s/ringbuf.hpp +++ b/include/lo2s/ringbuf.hpp @@ -163,6 +163,11 @@ class RingBufWriter : public ShmRingbuf std::byte* reserve(size_t ev_size) { + if (ev_size == 0) + { + return nullptr; + } + // No other reservation can be active! assert(reserved_size_ == 0); @@ -201,6 +206,11 @@ class RingBufReader : public ShmRingbuf std::byte* get(size_t size) { + if (size == 0) + { + return nullptr; + } + if (!can_be_loaded(size)) { return nullptr; @@ -210,6 +220,11 @@ class RingBufReader : public ShmRingbuf void pop(size_t ev_size) { + if (ev_size == 0) + { + return; + } + // Calling pop() without trying to get() data from the ringbuffer first is an error assert(can_be_loaded(ev_size)); diff --git a/src/monitor/process_monitor_main.cpp b/src/monitor/process_monitor_main.cpp index 0a7876ef..7927c801 100644 --- a/src/monitor/process_monitor_main.cpp +++ b/src/monitor/process_monitor_main.cpp @@ -119,7 +119,7 @@ static void drop_privileges() assert(getgid() != 0); } -std::vector to_vector_of_c_str(std::vector vec) +std::vector to_vector_of_c_str(const std::vector& vec) { std::vector res; std::transform(vec.begin(), vec.end(), std::back_inserter(res), [](const std::string& s) {