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

@@ -181,7 +181,7 @@ command_neopixel_update(uint32_t *args)
struct neopixel_s *n = oid_lookup(oid, command_config_neopixel);
uint_fast16_t pos = args[1];
uint_fast8_t data_len = args[2];
uint8_t *data = (void*)(size_t)args[3];
uint8_t *data = command_decode_ptr(args[3]);
if (pos & 0x8000 || pos + data_len > n->data_size)
shutdown("Invalid neopixel update command");
memcpy(&n->data[pos], data, data_len);