From: Tedd Ho-Jeong An Date: Fri, 1 Jul 2022 00:43:51 +0000 (-0700) Subject: tools/btmgmt: Fix errors reported by scan-build X-Git-Tag: accepted/tizen/unified/20230608.164325~169 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3cc453c338288117dd33b42136ccf5d0f1072c1e;p=platform%2Fupstream%2Fbluez.git tools/btmgmt: Fix errors reported by scan-build This patch fixes the errors reported by the scan-build. tools/btmgmt.c:2699:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores] argc -= optind; ^ ~~~~~~ tools/btmgmt.c:2859:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores] argc -= optind; ^ ~~~~~~ tools/btmgmt.c:2860:2: warning: Value stored to 'argv' is never read [deadcode.DeadStores] argv += optind; ^ ~~~~~~ tools/btmgmt.c:2934:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores] argc -= optind; ^ ~~~~~~ tools/btmgmt.c:2935:2: warning: Value stored to 'argv' is never read [deadcode.DeadStores] argv += optind; ^ ~~~~~~ tools/btmgmt.c:3000:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores] argc -= optind; ^ ~~~~~~ tools/btmgmt.c:3001:2: warning: Value stored to 'argv' is never read [deadcode.DeadStores] argv += optind; ^ ~~~~~~ tools/btmgmt.c:3261:11: warning: Value stored to 'index' during its initialization is never read [deadcode.DeadStores] uint16_t index = mgmt_index; ^~~~~ ~~~~~~~~~~ tools/btmgmt.c:3450:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores] argc -= optind; ^ ~~~~~~ tools/btmgmt.c:3451:2: warning: Value stored to 'argv' is never read [deadcode.DeadStores] argv += optind; ^ ~~~~~~ tools/btmgmt.c:4822:2: warning: Null pointer passed to 2nd parameter expecting 'nonnull' [core.NonNullParamChecker] memcpy(cp->data + uuid_bytes, adv_data, adv_len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tools/btmgmt.c:4823:2: warning: Null pointer passed to 2nd parameter expecting 'nonnull' [core.NonNullParamChecker] memcpy(cp->data + uuid_bytes + adv_len, scan_rsp, scan_rsp_len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tools/btmgmt.c:5244:2: warning: Null pointer passed to 2nd parameter expecting 'nonnull' [core.NonNullParamChecker] memcpy(cp->data + uuid_bytes, adv_data, adv_len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tools/btmgmt.c:5245:2: warning: Null pointer passed to 2nd parameter expecting 'nonnull' [core.NonNullParamChecker] memcpy(cp->data + uuid_bytes + adv_len, scan_rsp, scan_rsp_len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Manika Shrivastava Signed-off-by: Ayush Garg --- diff --git a/tools/btmgmt.c b/tools/btmgmt.c index e27dc49..94e1c44 100755 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -2695,7 +2695,6 @@ static void cmd_disconnect(int argc, char **argv) } } - argc -= optind; argv += optind; optind = 0; @@ -2855,8 +2854,6 @@ static void cmd_find_service(int argc, char **argv) } } - argc -= optind; - argv += optind; optind = 0; cp = (void *) buf; @@ -2930,8 +2927,6 @@ static void cmd_find(int argc, char **argv) } } - argc -= optind; - argv += optind; optind = 0; memset(&cp, 0, sizeof(cp)); @@ -2996,8 +2991,6 @@ static void cmd_stop_find(int argc, char **argv) } } - argc -= optind; - argv += optind; optind = 0; memset(&cp, 0, sizeof(cp)); @@ -3257,7 +3250,7 @@ static void cmd_unpair(int argc, char **argv) struct mgmt_cp_unpair_device cp; uint8_t type = BDADDR_BREDR; int opt; - uint16_t index = mgmt_index; + uint16_t index; while ((opt = getopt_long(argc, argv, "+t:h", unpair_options, NULL)) != -1) { @@ -3446,8 +3439,6 @@ static void cmd_irks(int argc, char **argv) } } - argc -= optind; - argv += optind; optind = 0; cp->irk_count = cpu_to_le16(count); @@ -4818,8 +4809,11 @@ static void cmd_add_adv(int argc, char **argv) memcpy(cp->data + 2, uuids, uuid_bytes - 2); } - memcpy(cp->data + uuid_bytes, adv_data, adv_len); - memcpy(cp->data + uuid_bytes + adv_len, scan_rsp, scan_rsp_len); + if (adv_len) + memcpy(cp->data + uuid_bytes, adv_data, adv_len); + + if (scan_rsp_len) + memcpy(cp->data + uuid_bytes + adv_len, scan_rsp, scan_rsp_len); if (!mgmt_send(mgmt, MGMT_OP_ADD_ADVERTISING, index, cp_len, cp, add_adv_rsp, NULL, NULL)) { @@ -5240,8 +5234,11 @@ static void cmd_add_ext_adv_data(int argc, char **argv) memcpy(cp->data + 2, uuids, uuid_bytes - 2); } - memcpy(cp->data + uuid_bytes, adv_data, adv_len); - memcpy(cp->data + uuid_bytes + adv_len, scan_rsp, scan_rsp_len); + if (adv_len) + memcpy(cp->data + uuid_bytes, adv_data, adv_len); + + if (scan_rsp_len) + memcpy(cp->data + uuid_bytes + adv_len, scan_rsp, scan_rsp_len); if (!mgmt_send(mgmt, MGMT_OP_ADD_EXT_ADV_DATA, index, cp_len, cp, add_ext_adv_data_rsp, NULL, NULL)) {