command: Add command_decode_ptr() helper

Add a helper function to convert from a string buffer passed in the
args[] parameter to an actual pointer.  This avoids all the callers
needing to perfrom pointer manipulation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-10-29 23:54:17 -04:00
parent aaf3dc6ac3
commit 473828ca6a
10 changed files with 38 additions and 30 deletions

View file

@ -15,6 +15,18 @@
static uint8_t next_sequence = MESSAGE_DEST;
static uint32_t
command_encode_ptr(void *p)
{
return (size_t)p;
}
void *
command_decode_ptr(uint32_t v)
{
return (void*)(size_t)v;
}
/****************************************************************
* Binary message parsing
@ -78,7 +90,7 @@ command_parsef(uint8_t *p, uint8_t *maxend
if (p + len > maxend)
goto error;
*args++ = len;
*args++ = (size_t)p;
*args++ = command_encode_ptr(p);
p += len;
break;
}