From f8bd8b97bea9273d166efdc06c3a6a54fc24ffdb Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 13 Aug 2017 16:48:27 -0400 Subject: 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 --- src/command.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index 3e5ef4c9..8780ae8a 100644 --- a/src/command.c +++ b/src/command.c @@ -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); -- cgit v1.2.3-70-g09d2