From 8cd06fb6a794985f5bf987a12f4c6f1f7f0d9cb3 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 1 Mar 2024 11:06:15 +0100 Subject: [PATCH] hfp_ag+hfp_hf: fix warnings --- src/classic/hfp_ag.c | 8 +++++++- src/classic/hfp_hf.c | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c index e8863512a..a88d259dd 100644 --- a/src/classic/hfp_ag.c +++ b/src/classic/hfp_ag.c @@ -2627,6 +2627,7 @@ static void hfp_ag_hci_event_packet_handler(uint8_t packet_type, uint16_t channe void hfp_ag_init_codecs(uint8_t codecs_nr, const uint8_t * codecs){ btstack_assert(codecs_nr <= HFP_MAX_NUM_CODECS); + if (codecs_nr > HFP_MAX_NUM_CODECS) return; hfp_ag_codecs_nr = codecs_nr; uint8_t i; @@ -2641,13 +2642,18 @@ void hfp_ag_init_supported_features(uint32_t supported_features){ } void hfp_ag_init_ag_indicators(int ag_indicators_nr, const hfp_ag_indicator_t * ag_indicators){ + btstack_assert(ag_indicators_nr <= HFP_MAX_NUM_INDICATORS); + if (ag_indicators_nr > HFP_MAX_NUM_CODECS) return; + hfp_ag_indicators_nr = ag_indicators_nr; (void)memcpy(hfp_ag_indicators, ag_indicators, ag_indicators_nr * sizeof(hfp_ag_indicator_t)); } void hfp_ag_init_hf_indicators(int hf_indicators_nr, const hfp_generic_status_indicator_t * hf_indicators){ - if (hf_indicators_nr > HFP_MAX_NUM_INDICATORS) return; + btstack_assert(hf_indicators_nr <= HFP_MAX_NUM_INDICATORS); + if (hf_indicators_nr > HFP_MAX_NUM_CODECS) return; + hfp_ag_generic_status_indicators_nr = hf_indicators_nr; (void)memcpy(hfp_ag_generic_status_indicators, hf_indicators, hf_indicators_nr * sizeof(hfp_generic_status_indicator_t)); diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c index 556b5cfd3..970419a17 100644 --- a/src/classic/hfp_hf.c +++ b/src/classic/hfp_hf.c @@ -1550,6 +1550,7 @@ void hfp_hf_deinit(void){ void hfp_hf_init_codecs(uint8_t codecs_nr, const uint8_t * codecs){ btstack_assert(codecs_nr <= HFP_MAX_NUM_CODECS); + if (codecs_nr > HFP_MAX_NUM_CODECS) return; hfp_hf_codecs_nr = codecs_nr; uint8_t i; @@ -1564,6 +1565,7 @@ void hfp_hf_init_supported_features(uint32_t supported_features){ void hfp_hf_init_hf_indicators(int indicators_nr, const uint16_t * indicators){ btstack_assert(hfp_hf_indicators_nr < HFP_MAX_NUM_INDICATORS); + if (hfp_hf_indicators_nr > HFP_MAX_NUM_CODECS) return; hfp_hf_indicators_nr = indicators_nr; int i;