samples: reel_board/mesh_badge: Fix string parsing from buffer

This code was still incorrectly causing corrupt strings to be
generated. Now it should be correct.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2018-11-23 14:18:58 +02:00 committed by Carles Cufí
parent 66a2bf03ba
commit 2f030f94f4

View file

@ -313,6 +313,7 @@ static void vnd_hello(struct bt_mesh_model *model,
struct net_buf_simple *buf)
{
char str[32];
size_t len;
printk("Hello message from 0x%04x\n", ctx->addr);
@ -321,8 +322,9 @@ static void vnd_hello(struct bt_mesh_model *model,
return;
}
strncpy(str, buf->data, HELLO_MAX);
str[HELLO_MAX] = '\0';
len = min(buf->len, HELLO_MAX);
memcpy(str, buf->data, len);
str[len] = '\0';
board_add_hello(ctx->addr, str);