command: Don't pass max_size to command_encodef()

The command_encodef() can read the max_size parameter directly from
the 'struct command_encoder' passed into it.  Also, there is no need
to check that a message will fit in a buffer if the buffer is declared
to be MESSAGE_MAX in size.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-08-13 16:48:27 -04:00
parent f3da473285
commit f8bd8b97be
7 changed files with 24 additions and 29 deletions

View file

@ -94,14 +94,14 @@ error:
// Encode a message
uint8_t
command_encodef(char *buf, uint8_t buf_len
, const struct command_encoder *ce, va_list args)
command_encodef(char *buf, const struct command_encoder *ce, va_list args)
{
if (buf_len <= MESSAGE_MIN)
uint8_t max_size = READP(ce->max_size);
if (max_size <= MESSAGE_MIN)
// Ack/Nak message
return buf_len;
return max_size;
char *p = &buf[MESSAGE_HEADER_SIZE];
char *maxend = &p[buf_len - MESSAGE_MIN];
char *maxend = &p[max_size - MESSAGE_MIN];
uint8_t num_params = READP(ce->num_params);
const uint8_t *param_types = READP(ce->param_types);
*p++ = READP(ce->msg_id);