From 7e5c235b9da628ceea3a5bb3f9de400c23a8a0b7 Mon Sep 17 00:00:00 2001 From: Alexey Gerenkov Date: Thu, 14 Jun 2018 19:11:21 +0300 Subject: [PATCH 01/15] app_trace: Fix tmo initialization --- components/app_trace/include/esp_app_trace_util.h | 1 + 1 file changed, 1 insertion(+) diff --git a/components/app_trace/include/esp_app_trace_util.h b/components/app_trace/include/esp_app_trace_util.h index e689d4502c..6376008c2f 100644 --- a/components/app_trace/include/esp_app_trace_util.h +++ b/components/app_trace/include/esp_app_trace_util.h @@ -41,6 +41,7 @@ static inline void esp_apptrace_tmo_init(esp_apptrace_tmo_t *tmo, uint32_t user_ { tmo->start = portGET_RUN_TIME_COUNTER_VALUE(); tmo->tmo = user_tmo; + tmo->elapsed = 0; } /** From 946a823ccbe5038a1bfd78d067443bafed6bf3eb Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 7 Aug 2018 23:26:05 +0300 Subject: [PATCH 02/15] syscalls: fix type conversion for _raise_r stub --- components/newlib/syscall_table.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/newlib/syscall_table.c b/components/newlib/syscall_table.c index 624ffcffab..2b3e4ed152 100644 --- a/components/newlib/syscall_table.c +++ b/components/newlib/syscall_table.c @@ -41,6 +41,10 @@ extern int _scanf_float(struct _reent *rptr, FILE *fp, va_list *ap); +static void raise_r_stub(struct _reent *rptr) +{ + _raise_r(rptr, 0); +} static struct syscall_stub_table s_stub_table = { .__getreent = &__getreent, @@ -53,7 +57,7 @@ static struct syscall_stub_table s_stub_table = { ._rename_r = &esp_vfs_rename, ._times_r = &_times_r, ._gettimeofday_r = &_gettimeofday_r, - ._raise_r = (void (*)(struct _reent *r)) &_raise_r, + ._raise_r = &raise_r_stub, ._unlink_r = &esp_vfs_unlink, ._link_r = &esp_vfs_link, ._stat_r = &esp_vfs_stat, From fc0c110efd24b2a9e44c5bd239cdb066b3398347 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 28 Aug 2018 12:22:40 +0800 Subject: [PATCH 03/15] driver: test: fix memset out of bounds in spi_master test --- components/driver/test/test_spi_master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/driver/test/test_spi_master.c b/components/driver/test/test_spi_master.c index 8e245b526d..9b82477d09 100644 --- a/components/driver/test/test_spi_master.c +++ b/components/driver/test/test_spi_master.c @@ -579,7 +579,7 @@ TEST_CASE("SPI Master DMA test, TX and RX in different regions", "[spi]") ESP_LOGI(TAG, "iram: %p, dram: %p", data_iram, data_dram); ESP_LOGI(TAG, "drom: %p, malloc: %p", data_drom, data_malloc); - memset(trans, 0, 6*sizeof(spi_transaction_t)); + memset(trans, 0, sizeof(trans)); trans[0].length = 320*8, trans[0].tx_buffer = data_iram; From 9ba5896d868bfbd94fa9893c1991ff906a9420e2 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 29 Aug 2018 11:26:44 +0800 Subject: [PATCH 04/15] driver, ethernet: fix non-static inline functions See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81734 --- components/driver/test/test_rmt.c | 2 +- components/ethernet/emac_dev.h | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/driver/test/test_rmt.c b/components/driver/test/test_rmt.c index de9937e3aa..9ee803dd91 100644 --- a/components/driver/test/test_rmt.c +++ b/components/driver/test/test_rmt.c @@ -88,7 +88,7 @@ static void fill_item_end(rmt_item32_t* item) /** * @brief Check whether duration is around target_us */ -inline bool check_in_range(int duration_ticks, int target_us, int margin_us) +static inline bool check_in_range(int duration_ticks, int target_us, int margin_us) { if(( ITEM_DURATION(duration_ticks) < (target_us + margin_us)) && ( ITEM_DURATION(duration_ticks) > (target_us - margin_us))) { diff --git a/components/ethernet/emac_dev.h b/components/ethernet/emac_dev.h index 86202e1213..73bb627d0c 100644 --- a/components/ethernet/emac_dev.h +++ b/components/ethernet/emac_dev.h @@ -54,54 +54,54 @@ void emac_enable_flowctrl(void); void emac_disable_flowctrl(void); void emac_mac_enable_txrx(void); -uint32_t inline emac_read_tx_cur_reg(void) +static inline uint32_t emac_read_tx_cur_reg(void) { return REG_READ(EMAC_DMATXCURRDESC_REG); } -uint32_t inline emac_read_rx_cur_reg(void) +static inline uint32_t emac_read_rx_cur_reg(void) { return REG_READ(EMAC_DMARXCURRDESC_REG); } -void inline emac_poll_tx_cmd(void) +static inline void emac_poll_tx_cmd(void) { //write any to wake up dma REG_WRITE(EMAC_DMATXPOLLDEMAND_REG, 1); } -void inline emac_poll_rx_cmd(void) +static inline void emac_poll_rx_cmd(void) { //write any to wake up dma REG_WRITE(EMAC_DMARXPOLLDEMAND_REG, 1); } -void inline emac_disable_rx_intr(void) +static inline void emac_disable_rx_intr(void) { REG_CLR_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RIE); } -void inline emac_enable_rx_intr(void) +static inline void emac_enable_rx_intr(void) { REG_SET_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RIE); } -void inline emac_disable_rx_unavail_intr(void) +static inline void emac_disable_rx_unavail_intr(void) { REG_CLR_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RBUE); } -void inline emac_enable_rx_unavail_intr(void) +static inline void emac_enable_rx_unavail_intr(void) { REG_SET_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RBUE); } -void IRAM_ATTR inline emac_send_pause_frame_enable(void) +static inline void IRAM_ATTR emac_send_pause_frame_enable(void) { REG_SET_BIT(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_SBD_FLOWCTRL); } -void inline emac_send_pause_zero_frame_enable(void) +static inline void emac_send_pause_zero_frame_enable(void) { REG_CLR_BIT(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_SBD_FLOWCTRL); } From 324004f7b370d6982035ad911b0ce0c5eb1afc8c Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 28 Aug 2018 12:23:27 +0800 Subject: [PATCH 05/15] spiffs: test: check for truncation in snprintf call --- components/spiffs/test/test_spiffs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/spiffs/test/test_spiffs.c b/components/spiffs/test/test_spiffs.c index 60bca410bd..cb2164ac1f 100644 --- a/components/spiffs/test/test_spiffs.c +++ b/components/spiffs/test/test_spiffs.c @@ -291,7 +291,8 @@ void test_spiffs_readdir_many_files(const char* dir_prefix) if (!de) { break; } - snprintf(file_name, sizeof(file_name), "%s/%s", dir_prefix, de->d_name); + int len = snprintf(file_name, sizeof(file_name), "%s/%s", dir_prefix, de->d_name); + assert(len < sizeof(file_name)); unlink(file_name); } } From c3123b00aedf8f3e7e43933be7f74e98947e013d Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 28 Aug 2018 21:34:44 +0800 Subject: [PATCH 06/15] examples/spi_slave: check for truncation in snprintf call Also fix character array initializer --- .../peripherals/spi_slave/sender/main/app_main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/peripherals/spi_slave/sender/main/app_main.c b/examples/peripherals/spi_slave/sender/main/app_main.c index b1e37dd496..c3eb565927 100644 --- a/examples/peripherals/spi_slave/sender/main/app_main.c +++ b/examples/peripherals/spi_slave/sender/main/app_main.c @@ -118,8 +118,8 @@ void app_main() }; int n=0; - char sendbuf[128]=""; - char recvbuf[128]=""; + char sendbuf[128] = {0}; + char recvbuf[128] = {0}; spi_transaction_t t; memset(&t, 0, sizeof(t)); @@ -143,8 +143,12 @@ void app_main() xSemaphoreGive(rdySem); while(1) { - snprintf(sendbuf, 128, "Sender, transmission no. %04i. Last time, I received: \"%s\"", n, recvbuf); - t.length=128*8; //128 bytes + int res = snprintf(sendbuf, sizeof(sendbuf), + "Sender, transmission no. %04i. Last time, I received: \"%s\"", n, recvbuf); + if (res >= sizeof(sendbuf)) { + printf("Data truncated\n"); + } + t.length=sizeof(sendbuf)*8; t.tx_buffer=sendbuf; t.rx_buffer=recvbuf; //Wait for slave to be ready for next byte before sending From 6af721e8e4a221b5e3e87f15fef90035c16ed6df Mon Sep 17 00:00:00 2001 From: Anton Maklakov Date: Wed, 29 Aug 2018 00:54:41 +0700 Subject: [PATCH 07/15] examples/bluetooth: Fix incompatible cast --- .../main/example_spp_vfs_acceptor_demo.c | 7 +++++-- .../main/example_spp_vfs_initiator_demo.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c b/examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c index 51c23c094e..f14d394484 100644 --- a/examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c +++ b/examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c @@ -67,8 +67,11 @@ static void spp_read_handle(void * param) spp_wr_task_shut_down(); } -static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) +static void esp_spp_cb(uint16_t e, void *p) { + esp_spp_cb_event_t event = e; + esp_spp_cb_param_t *param = p; + switch (event) { case ESP_SPP_INIT_EVT: ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT"); @@ -102,7 +105,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) static void esp_spp_stack_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { - spp_task_work_dispatch((spp_task_cb_t)esp_spp_cb, event, param, sizeof(esp_spp_cb_param_t), NULL); + spp_task_work_dispatch(esp_spp_cb, event, param, sizeof(esp_spp_cb_param_t), NULL); } void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) diff --git a/examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c b/examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c index f5ef880a7b..fa144215ef 100644 --- a/examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c +++ b/examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c @@ -105,8 +105,11 @@ static bool get_name_from_eir(uint8_t *eir, char *bdname, uint8_t *bdname_len) return false; } -static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) +static void esp_spp_cb(uint16_t e, void *p) { + esp_spp_cb_event_t event = e; + esp_spp_cb_param_t *param = p; + switch (event) { case ESP_SPP_INIT_EVT: ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT"); @@ -198,7 +201,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa static void esp_spp_stack_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { - spp_task_work_dispatch((spp_task_cb_t)esp_spp_cb, event, param, sizeof(esp_spp_cb_param_t), NULL); + spp_task_work_dispatch(esp_spp_cb, event, param, sizeof(esp_spp_cb_param_t), NULL); } void app_main() From 536df958ad57acc7f360e9b246bd22f500dc5248 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 28 Aug 2018 18:21:44 +0800 Subject: [PATCH 08/15] bt/btm: fix misplaced debug statement --- components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c b/components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c index ae55635b5d..ed56459e4a 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c @@ -331,8 +331,8 @@ void btm_ble_scan_pf_cmpl_cback(tBTM_VSC_CMPL *p_params) break; } + BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback: calling the cback: %d", cb_evt); switch (cb_evt) { - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback: calling the cback: %d", cb_evt); case BTM_BLE_FILT_CFG: if (NULL != p_scan_cfg_cback) { p_scan_cfg_cback(action, cond_type, num_avail, status, ref_value); From 9fbe42c0f18682bbf1bdedf8dff30f9bd2513428 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 28 Aug 2018 18:18:31 +0800 Subject: [PATCH 09/15] bt/bta: fix returning value from function returning void --- components/bt/bluedroid/bta/gatt/bta_gattc_cache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c b/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c index 90a9d13502..2d6e9ee158 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c @@ -1291,7 +1291,9 @@ void bta_gattc_get_db_with_opration(UINT16 conn_id, tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (p_clcb == NULL) { - return NULL; + *count = 0; + *char_db = NULL; + return; } tBTA_GATTC_SERV *p_srcb = p_clcb->p_srcb; @@ -1671,7 +1673,8 @@ void bta_gattc_get_db_size_with_type_handle(UINT16 conn_id, bt_gatt_db_attribute tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (p_clcb == NULL) { - return NULL; + *count = 0; + return; } tBTA_GATTC_SERV *p_srcb = p_clcb->p_srcb; From 033b694128a42dbfc3b9c8b15ff966bc3869eda1 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 28 Aug 2018 17:31:18 +0800 Subject: [PATCH 10/15] bt/a2dp: fix incorrect return type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit res was declared as “bool” so expression ((count == 0) ? A2D_SET_ONE_BIT : A2D_SET_MULTL_BIT) always evaluated to “true”, and was implicitly converted to A2D_SET_ONE_BIT. --- components/bt/bluedroid/stack/a2dp/a2d_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/bt/bluedroid/stack/a2dp/a2d_api.c b/components/bt/bluedroid/stack/a2dp/a2d_api.c index 73b174e614..937e46b1e1 100644 --- a/components/bt/bluedroid/stack/a2dp/a2d_api.c +++ b/components/bt/bluedroid/stack/a2dp/a2d_api.c @@ -352,8 +352,8 @@ UINT8 A2D_SetTraceLevel (UINT8 new_level) ******************************************************************************/ UINT8 A2D_BitsSet(UINT8 num) { - UINT8 count; - BOOLEAN res; + UINT8 count; + UINT8 res; if (num == 0) { res = A2D_SET_ZERO_BIT; } else { From ed546797d0892e8322c526e52b75e430fbb35398 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 29 Aug 2018 12:52:03 +0800 Subject: [PATCH 11/15] =?UTF-8?q?heap:=20test:=20don=E2=80=99t=20warn=20ab?= =?UTF-8?q?out=20oversized=20mallocs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/heap/test/test_malloc.c | 35 +++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/components/heap/test/test_malloc.c b/components/heap/test/test_malloc.c index 1e13ce3603..52dc5d171a 100644 --- a/components/heap/test/test_malloc.c +++ b/components/heap/test/test_malloc.c @@ -88,23 +88,42 @@ TEST_CASE("Check if reserved DMA pool still can allocate even when malloc()'ed m #endif + +/* As you see, we are desperately trying to outsmart the compiler, so that it + * doesn't warn about oversized allocations in the next two unit tests. + * To be removed when we switch to GCC 8.2 and add + * -Wno-alloc-size-larger-than=PTRDIFF_MAX to CFLAGS for this file. + */ +void* (*g_test_malloc_ptr)(size_t) = &malloc; +void* (*g_test_calloc_ptr)(size_t, size_t) = &calloc; + +void* test_malloc_wrapper(size_t size) +{ + return (*g_test_malloc_ptr)(size); +} + +void* test_calloc_wrapper(size_t count, size_t size) +{ + return (*g_test_calloc_ptr)(count, size); +} + TEST_CASE("alloc overflows should all fail", "[heap]") { /* allocates 8 bytes */ - TEST_ASSERT_NULL(calloc(SIZE_MAX / 2 + 4, 2)); + TEST_ASSERT_NULL(test_calloc_wrapper(SIZE_MAX / 2 + 4, 2)); /* will overflow if any poisoning is enabled (should fail for sensible OOM reasons, otherwise) */ - TEST_ASSERT_NULL(malloc(SIZE_MAX - 1)); - TEST_ASSERT_NULL(calloc(SIZE_MAX - 1, 1)); + TEST_ASSERT_NULL(test_malloc_wrapper(SIZE_MAX - 1)); + TEST_ASSERT_NULL(test_calloc_wrapper(SIZE_MAX - 1, 1)); } TEST_CASE("unreasonable allocs should all fail", "[heap]") { - TEST_ASSERT_NULL(calloc(16, 1024*1024)); - TEST_ASSERT_NULL(malloc(16*1024*1024)); - TEST_ASSERT_NULL(malloc(SIZE_MAX / 2)); - TEST_ASSERT_NULL(malloc(SIZE_MAX - 256)); - TEST_ASSERT_NULL(malloc(xPortGetFreeHeapSize() - 1)); + TEST_ASSERT_NULL(test_calloc_wrapper(16, 1024*1024)); + TEST_ASSERT_NULL(test_malloc_wrapper(16*1024*1024)); + TEST_ASSERT_NULL(test_malloc_wrapper(SIZE_MAX / 2)); + TEST_ASSERT_NULL(test_malloc_wrapper(SIZE_MAX - 256)); + TEST_ASSERT_NULL(test_malloc_wrapper(xPortGetFreeHeapSize() - 1)); } From e8eb8cb2a42fe63052bb3923b9a3560558e2bc79 Mon Sep 17 00:00:00 2001 From: Anton Maklakov Date: Wed, 29 Aug 2018 12:54:29 +0800 Subject: [PATCH 12/15] bluetooth: fix missing braces and indentation --- components/bt/bluedroid/bta/gatt/bta_gattc_utils.c | 3 ++- components/bt/bluedroid/osi/list.c | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c index 774134478b..37193438a8 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c @@ -578,13 +578,14 @@ void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id, for (i = 0 ; i < BTA_GATTC_NOTIF_REG_MAX; i ++) { if (p_clrcb->notif_reg[i].in_use && !bdcmp(p_clrcb->notif_reg[i].remote_bda, remote_bda)) - + { /* It's enough to get service or characteristic handle, as * clear boundaries are always around service. */ handle = p_clrcb->notif_reg[i].handle; if (handle >= start_handle && handle <= end_handle) memset(&p_clrcb->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG)); + } } } } else { diff --git a/components/bt/bluedroid/osi/list.c b/components/bt/bluedroid/osi/list.c index eb46cda45e..ede10976b4 100644 --- a/components/bt/bluedroid/osi/list.c +++ b/components/bt/bluedroid/osi/list.c @@ -99,13 +99,13 @@ list_node_t *list_back_node(const list_t *list) { } bool list_insert_after(list_t *list, list_node_t *prev_node, void *data) { - assert(list != NULL); - assert(prev_node != NULL); - assert(data != NULL); + assert(list != NULL); + assert(prev_node != NULL); + assert(data != NULL); - list_node_t *node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t)); - if (!node) - return false; + list_node_t *node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t)); + if (!node) + return false; node->next = prev_node->next; node->data = data; From 779bce7681adb9d86bba6d19fc56e3d9e50cb131 Mon Sep 17 00:00:00 2001 From: Anton Maklakov Date: Wed, 29 Aug 2018 12:55:07 +0800 Subject: [PATCH 13/15] bluetooth: fix incorrect memset size --- components/bt/bluedroid/stack/smp/p_256_curvepara.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/bt/bluedroid/stack/smp/p_256_curvepara.c b/components/bt/bluedroid/stack/smp/p_256_curvepara.c index 1761d58483..0b79770563 100644 --- a/components/bt/bluedroid/stack/smp/p_256_curvepara.c +++ b/components/bt/bluedroid/stack/smp/p_256_curvepara.c @@ -41,8 +41,8 @@ void p_256_init_curve(UINT32 keyLength) ec->p[1] = 0xFFFFFFFF; ec->p[0] = 0xFFFFFFFF; - memset(ec->omega, 0, KEY_LENGTH_DWORDS_P256); - memset(ec->a, 0, KEY_LENGTH_DWORDS_P256); + memset(ec->omega, 0, KEY_LENGTH_DWORDS_P256 * sizeof(ec->omega[0])); + memset(ec->a, 0, KEY_LENGTH_DWORDS_P256 * sizeof(ec->a[0])); ec->a_minus3 = TRUE; From 8c040e749fa442c67ed4e6ebeed05af688fdfdbf Mon Sep 17 00:00:00 2001 From: Anton Maklakov Date: Wed, 29 Aug 2018 12:55:28 +0800 Subject: [PATCH 14/15] bluetooth: fix format overflow warnings --- components/bt/bluedroid/osi/config.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/components/bt/bluedroid/osi/config.c b/components/bt/bluedroid/osi/config.c index 55e782ca6a..55a3b3d4b0 100644 --- a/components/bt/bluedroid/osi/config.c +++ b/components/bt/bluedroid/osi/config.c @@ -336,7 +336,8 @@ static int get_config_size_from_flash(nvs_handle fp) assert(fp != 0); esp_err_t err; - char *keyname = osi_calloc(sizeof(CONFIG_KEY) + 1); + const size_t keyname_bufsz = sizeof(CONFIG_KEY) + 5 + 1; // including log10(sizeof(i)) + char *keyname = osi_calloc(keyname_bufsz); if (!keyname){ OSI_TRACE_ERROR("%s, malloc error\n", __func__); return 0; @@ -344,7 +345,7 @@ static int get_config_size_from_flash(nvs_handle fp) size_t length = CONFIG_FILE_DEFAULE_LENGTH; size_t total_length = 0; uint16_t i = 0; - snprintf(keyname, sizeof(CONFIG_KEY) + 1, "%s%d", CONFIG_KEY, 0); + snprintf(keyname, keyname_bufsz, "%s%d", CONFIG_KEY, 0); err = nvs_get_blob(fp, keyname, NULL, &length); if (err == ESP_ERR_NVS_NOT_FOUND) { osi_free(keyname); @@ -358,7 +359,7 @@ static int get_config_size_from_flash(nvs_handle fp) total_length += length; while (length == CONFIG_FILE_MAX_SIZE) { length = CONFIG_FILE_DEFAULE_LENGTH; - snprintf(keyname, sizeof(CONFIG_KEY) + 1, "%s%d", CONFIG_KEY, ++i); + snprintf(keyname, keyname_bufsz, "%s%d", CONFIG_KEY, ++i); err = nvs_get_blob(fp, keyname, NULL, &length); if (err == ESP_ERR_NVS_NOT_FOUND) { @@ -385,7 +386,8 @@ bool config_save(const config_t *config, const char *filename) int err_code = 0; nvs_handle fp; char *line = osi_calloc(1024); - char *keyname = osi_calloc(sizeof(CONFIG_KEY) + 1); + const size_t keyname_bufsz = sizeof(CONFIG_KEY) + 5 + 1; // including log10(sizeof(i)) + char *keyname = osi_calloc(keyname_bufsz); int config_size = get_config_size(config); char *buf = osi_calloc(config_size + 100); if (!line || !buf || !keyname) { @@ -430,7 +432,7 @@ bool config_save(const config_t *config, const char *filename) } buf[w_cnt_total] = '\0'; if (w_cnt_total < CONFIG_FILE_MAX_SIZE) { - snprintf(keyname, sizeof(CONFIG_KEY)+1, "%s%d", CONFIG_KEY, 0); + snprintf(keyname, keyname_bufsz, "%s%d", CONFIG_KEY, 0); err = nvs_set_blob(fp, keyname, buf, w_cnt_total); if (err != ESP_OK) { nvs_close(fp); @@ -441,7 +443,7 @@ bool config_save(const config_t *config, const char *filename) uint count = (w_cnt_total / CONFIG_FILE_MAX_SIZE); for (int i = 0; i <= count; i++) { - snprintf(keyname, sizeof(CONFIG_KEY)+1, "%s%d", CONFIG_KEY, i); + snprintf(keyname, keyname_bufsz, "%s%d", CONFIG_KEY, i); if (i == count) { err = nvs_set_blob(fp, keyname, buf + i*CONFIG_FILE_MAX_SIZE, w_cnt_total - i*CONFIG_FILE_MAX_SIZE); OSI_TRACE_DEBUG("save keyname = %s, i = %d, %d\n", keyname, i, w_cnt_total - i*CONFIG_FILE_MAX_SIZE); @@ -518,14 +520,15 @@ static void config_parse(nvs_handle fp, config_t *config) size_t total_length = 0; char *line = osi_calloc(1024); char *section = osi_calloc(1024); - char *keyname = osi_calloc(sizeof(CONFIG_KEY) + 1); + const size_t keyname_bufsz = sizeof(CONFIG_KEY) + 5 + 1; // including log10(sizeof(i)) + char *keyname = osi_calloc(keyname_bufsz); int buf_size = get_config_size_from_flash(fp); char *buf = osi_calloc(buf_size + 100); if (!line || !section || !buf || !keyname) { err_code |= 0x01; goto error; } - snprintf(keyname, sizeof(CONFIG_KEY)+1, "%s%d", CONFIG_KEY, 0); + snprintf(keyname, keyname_bufsz, "%s%d", CONFIG_KEY, 0); err = nvs_get_blob(fp, keyname, buf, &length); if (err == ESP_ERR_NVS_NOT_FOUND) { goto error; @@ -537,7 +540,7 @@ static void config_parse(nvs_handle fp, config_t *config) total_length += length; while (length == CONFIG_FILE_MAX_SIZE) { length = CONFIG_FILE_DEFAULE_LENGTH; - snprintf(keyname, sizeof(CONFIG_KEY) + 1, "%s%d", CONFIG_KEY, ++i); + snprintf(keyname, keyname_bufsz, "%s%d", CONFIG_KEY, ++i); err = nvs_get_blob(fp, keyname, buf + CONFIG_FILE_MAX_SIZE * i, &length); if (err == ESP_ERR_NVS_NOT_FOUND) { From 61dc37a6c3bab49c331a6f935e97bf281b31fee7 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 29 Aug 2018 12:59:30 +0800 Subject: [PATCH 15/15] examples/bluetooth: add fallthrough annotations --- examples/bluetooth/a2dp_gatts_coex/main/bt_app_av.c | 1 + examples/bluetooth/a2dp_sink/main/bt_app_av.c | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/bluetooth/a2dp_gatts_coex/main/bt_app_av.c b/examples/bluetooth/a2dp_gatts_coex/main/bt_app_av.c index c015bfa621..2bf069da2c 100644 --- a/examples/bluetooth/a2dp_gatts_coex/main/bt_app_av.c +++ b/examples/bluetooth/a2dp_gatts_coex/main/bt_app_av.c @@ -79,6 +79,7 @@ void bt_app_rc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param switch (event) { case ESP_AVRC_CT_METADATA_RSP_EVT: bt_app_alloc_meta_buffer(param); + /* fall through */ case ESP_AVRC_CT_CONNECTION_STATE_EVT: case ESP_AVRC_CT_PASSTHROUGH_RSP_EVT: case ESP_AVRC_CT_CHANGE_NOTIFY_EVT: diff --git a/examples/bluetooth/a2dp_sink/main/bt_app_av.c b/examples/bluetooth/a2dp_sink/main/bt_app_av.c index 64d554fd91..af67c5aa98 100644 --- a/examples/bluetooth/a2dp_sink/main/bt_app_av.c +++ b/examples/bluetooth/a2dp_sink/main/bt_app_av.c @@ -75,6 +75,7 @@ void bt_app_rc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param switch (event) { case ESP_AVRC_CT_METADATA_RSP_EVT: bt_app_alloc_meta_buffer(param); + /* fall through */ case ESP_AVRC_CT_CONNECTION_STATE_EVT: case ESP_AVRC_CT_PASSTHROUGH_RSP_EVT: case ESP_AVRC_CT_CHANGE_NOTIFY_EVT: