From 353f893d952a7abdc2304b8d7f4274a86003c717 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 10 Jun 2020 10:47:30 +0800 Subject: [PATCH] ble_mesh: Fix wrong log output with bt_hex - This issue was introduced in the commit: a788e7cd3db4172fce495d2e418adea79 which updated the bt_hex() function incorrectly. - And in bt_hex(), we use 2 for the two-dimensional array, because currently at most two bt_hex() will be used at the same time. Also this will save some DRAM compared with using 4. --- components/bt/esp_ble_mesh/mesh_common/mesh_util.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_util.c b/components/bt/esp_ble_mesh/mesh_common/mesh_util.c index 83949594b5..7e6ce15acf 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_util.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_util.c @@ -17,11 +17,16 @@ const char *bt_hex(const void *buf, size_t len) { static const char hex[] = "0123456789abcdef"; - static char str[129]; + static char hexbufs[2][129]; + static u8_t curbuf; const u8_t *b = buf; + char *str = NULL; int i; - len = MIN(len, (sizeof(str) - 1) / 2); + str = hexbufs[curbuf++]; + curbuf %= ARRAY_SIZE(hexbufs); + + len = MIN(len, (sizeof(hexbufs[0]) - 1) / 2); for (i = 0; i < len; i++) { str[i * 2] = hex[b[i] >> 4];