From 9951b94d40a11374575f9c533a5f62dedff7c4e3 Mon Sep 17 00:00:00 2001 From: Murilo Belluzzo Date: Sat, 25 Jun 2016 22:10:04 -0300 Subject: [PATCH] AP_HAL: Change the return type of 'peekiovec' Possible values are '0', '1' and '2' so uint8_t is a better fit. Also, invert 'if' condition so it's clear that is returning 0, 1 or 2. --- libraries/AP_HAL/utility/RingBuffer.cpp | 14 +++++++------- libraries/AP_HAL/utility/RingBuffer.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/AP_HAL/utility/RingBuffer.cpp b/libraries/AP_HAL/utility/RingBuffer.cpp index 2608b168be..76eb30df79 100644 --- a/libraries/AP_HAL/utility/RingBuffer.cpp +++ b/libraries/AP_HAL/utility/RingBuffer.cpp @@ -96,7 +96,7 @@ bool ByteBuffer::advance(uint32_t n) return true; } -int ByteBuffer::peekiovec(ByteBuffer::IoVec iovec[2], uint32_t len) +uint8_t ByteBuffer::peekiovec(ByteBuffer::IoVec iovec[2], uint32_t len) { if (len > available()) { len = available(); @@ -113,14 +113,14 @@ int ByteBuffer::peekiovec(ByteBuffer::IoVec iovec[2], uint32_t len) iovec[0].data = const_cast(b); iovec[0].len = n; - if (len > n) { - iovec[1].data = buf; - iovec[1].len = len - n; - - return 2; + if (len <= n) { + return 1; } - return 1; + iovec[1].data = buf; + iovec[1].len = len - n; + + return 2; } /* diff --git a/libraries/AP_HAL/utility/RingBuffer.h b/libraries/AP_HAL/utility/RingBuffer.h index b821f14ea1..9db1e561d0 100644 --- a/libraries/AP_HAL/utility/RingBuffer.h +++ b/libraries/AP_HAL/utility/RingBuffer.h @@ -74,13 +74,13 @@ public: uint32_t peekbytes(uint8_t *data, uint32_t len); // Similar to peekbytes(), but will fill out IoVec struct with - // both parts of the ring buffer if wraparound is happpening, or + // both parts of the ring buffer if wraparound is happening, or // just one part. Returns the number of parts written to. struct IoVec { uint8_t *data; uint32_t len; }; - int peekiovec(IoVec vec[2], uint32_t len); + uint8_t peekiovec(IoVec vec[2], uint32_t len); // Reserve `len` bytes and fills out `vec` with both parts of the // ring buffer (if wraparound is happening), or just one contiguous