diff --git a/libraries/AP_HAL/utility/RingBuffer.cpp b/libraries/AP_HAL/utility/RingBuffer.cpp index de33685688..afbdf76f7d 100644 --- a/libraries/AP_HAL/utility/RingBuffer.cpp +++ b/libraries/AP_HAL/utility/RingBuffer.cpp @@ -1,20 +1,17 @@ -#include "RingBuffer.h" #include #include -/* - implement a simple ringbuffer of bytes - */ +#include "RingBuffer.h" ByteBuffer::ByteBuffer(uint32_t _size) { - size = _size; - buf = new uint8_t[size]; + buf = (uint8_t*)malloc(_size); + size = buf ? _size : 0; } ByteBuffer::~ByteBuffer(void) { - delete [] buf; + free(buf); } /* @@ -26,10 +23,10 @@ void ByteBuffer::set_size(uint32_t _size) head = tail = 0; if (_size != size) { - size = _size; oldbuf = buf; - buf = new uint8_t[size]; - delete[] oldbuf; + buf = (uint8_t*)malloc(_size); + size = buf ? _size : 0; + free(oldbuf); } } @@ -41,8 +38,8 @@ uint32_t ByteBuffer::available(void) const uint32_t ByteBuffer::space(void) const { - uint32_t _head; - return (((_head=head) > tail)?(_head - tail) - 1:((size - tail) + _head) - 1); + uint32_t _head = head; + return size ? (_head > tail ? 0 : size) + _head - tail - 1 : 0; } bool ByteBuffer::empty(void) const