From 0998bdc0578f278e5a46ed89a5f19320a14e714a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Jan 2023 08:54:16 +1100 Subject: [PATCH] AP_HAL: check for null buffer in ObjectBuffer get_size() --- libraries/AP_HAL/utility/RingBuffer.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/AP_HAL/utility/RingBuffer.h b/libraries/AP_HAL/utility/RingBuffer.h index 311de1f61b..08492cfadf 100644 --- a/libraries/AP_HAL/utility/RingBuffer.h +++ b/libraries/AP_HAL/utility/RingBuffer.h @@ -129,6 +129,9 @@ public: // return size of ringbuffer uint32_t get_size(void) const { + if (buffer == nullptr) { + return 0; + } uint32_t size = buffer->get_size() / sizeof(T); return size>0?size-1:0; } @@ -291,6 +294,9 @@ public: // return size of ringbuffer uint32_t get_size(void) { WITH_SEMAPHORE(sem); + if (buffer == nullptr) { + return 0; + } uint32_t size = buffer->get_size() / sizeof(T); return size>0?size-1:0; }