BQ_BUFFER_SIZE macro correct?

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
flabbergast
Posts: 71
Joined: Sat Aug 22, 2015 1:22 pm

BQ_BUFFER_SIZE macro correct?

Post by flabbergast »

In hal/include/hal_buffers.h there's this definition:

Code: Select all

#define BQ_BUFFER_SIZE(n, size)                                             \
  ((size_t)(size) + ((sizeof (size_t)) * (size_t)(n)))

From what I could understand from the documentation of buffers queue, I thought it should compute how many bytes should be allocated for n buffers, each of size size. It does not do this (the parentheses are wrong for this); it looks like it allocates one buffer of size size plus a little bit.
Is this a bug, or do I understand the buffers queue wrong?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: BQ_BUFFER_SIZE macro correct?

Post by Giovanni »

The buffers should be long "size + sizeof(size)" because a size field is attached to each buffer.

Said that, the macro looks wrong... looks like a huge bug. Worth an update during weekend.

Giovanni
flabbergast
Posts: 71
Joined: Sat Aug 22, 2015 1:22 pm

Re: BQ_BUFFER_SIZE macro correct?

Post by flabbergast »

Thanks, that's what I thought it should do. Yes, it would be good to fix :)
Post Reply