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; }