From 473828ca6aef18c574b8665ae484513e5592af03 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 29 Oct 2020 23:54:17 -0400 Subject: 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 --- src/command.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index b0c7f882..e3167baf 100644 --- a/src/command.c +++ b/src/command.c @@ -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; } -- cgit v1.2.3-70-g09d2