AP_HAL: RingBuffer: fix macro expansion

Fix warning that reveals a real bug:

In file included from libraries/AP_HAL_Linux/UARTDriver.cpp:25:0:
libraries/AP_HAL_Linux/UARTDriver.cpp: In member function 'virtual bool Linux::UARTDriver::tx_pending()':
libraries/AP_HAL/utility/RingBuffer.h:21:35: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
 #define BUF_EMPTY(buf) buf##_head == buf##_tail
                                   ^
libraries/AP_HAL_Linux/UARTDriver.cpp:355:13: note: in expansion of macro 'BUF_EMPTY'
     return !BUF_EMPTY(_writebuf);

The problem is when there's a ! operator: without the parenthesis we would actually be doing

    return !_write_buf_head == _write_buf_tail

which is not what we want.
This commit is contained in:
Lucas De Marchi 2015-12-28 14:09:36 -02:00
parent fe8070bd51
commit 97022a4161
1 changed files with 1 additions and 1 deletions

View File

@ -18,7 +18,7 @@
*/
#define BUF_AVAILABLE(buf) ((buf##_head > (_tail=buf##_tail))? (buf##_size - buf##_head) + _tail: _tail - buf##_head)
#define BUF_SPACE(buf) (((_head=buf##_head) > buf##_tail)?(_head - buf##_tail) - 1:((buf##_size - buf##_tail) + _head) - 1)
#define BUF_EMPTY(buf) buf##_head == buf##_tail
#define BUF_EMPTY(buf) (buf##_head == buf##_tail)
#define BUF_ADVANCETAIL(buf, n) buf##_tail = (buf##_tail + n) % buf##_size
#define BUF_ADVANCEHEAD(buf, n) buf##_head = (buf##_head + n) % buf##_size