Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1121323iog; Thu, 30 Jun 2022 17:53:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sVaVvwO/puvJAO7WShIgeDJ5wB7d7BgIKqkmIDhPupe/WdmFuvhP4t5rwrU86FU2Szq/dq X-Received: by 2002:a05:6402:398:b0:435:6df7:b7e4 with SMTP id o24-20020a056402039800b004356df7b7e4mr15514527edv.306.1656636809835; Thu, 30 Jun 2022 17:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656636809; cv=none; d=google.com; s=arc-20160816; b=pllOZ3BVCnaMGedjNkntT1iSeEKcLNRBndV2rbbPWgdKqHFWIik9pCS9sA3QjR2DKq MJLZHK4ldd+9FdmJ1PYp/MEnfL+jF3wYQ8rDkvcmzMpq68n8qhvmWabfM2gbOOwP4OnJ S9ab7/HNjF2+bAfn80GoO+CZ0Z74uIcBCpYS6nXuYokJPVIzABWV10ICuepAuXhIoEG9 LKc/CNkCJqCULDvPz2/AcFRmkEgGkytjMsYavcMTPuF5kfAA01QMJiuzn1illg5DR4Vj cGi2IpCOL1/o+SbF3gSag1ovlkapFgzOMqItEn9i64hsEiVnwcmrNlFFfv01WGZyxdRq axBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=tldd8hQ2wUn25jo82acAyXTHIBMdYLaXJm4pX84uJh0=; b=QwNdKZpkZ+eC3Y6YssAyO5Pu//GKvdlcqjnExTzM82XlnsXZBZmhzsgZCAGeTOKV2z /UCnEWxjjRs+JeMeOyoP8tGGNEYGFdhZWGoyzNtEvJez2UJnBTRJx/5xve1cG0Xcs3c6 T10/MkK5Xxdr4CZlKWyCMiP4+zAwA4fPTprdiBGjVbKrPrxP9+WDYLegBMFkNtoIl4Qm zfYUVCuNEgDrac4TW9IweCjKplPluaxbbYx6g6bzyhTUhFWpZ7wMYazeboAige3E3O/o kmxbGAIvpIP9ywvz9ZRYAcOAWuLhTjeO3f36cIGbjTDuSaJ7a/QHOwdpDgBuipnhCvR4 uCjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OZ2R2vAb; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk37-20020a1709077fa500b00722ded34175si5999208ejc.560.2022.06.30.17.53.04; Thu, 30 Jun 2022 17:53:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OZ2R2vAb; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231640AbiGAAn5 (ORCPT + 99 others); Thu, 30 Jun 2022 20:43:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiGAAn4 (ORCPT ); Thu, 30 Jun 2022 20:43:56 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DDEC24BC4 for ; Thu, 30 Jun 2022 17:43:55 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id z14so984109pgh.0 for ; Thu, 30 Jun 2022 17:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tldd8hQ2wUn25jo82acAyXTHIBMdYLaXJm4pX84uJh0=; b=OZ2R2vAbl3j1N9ro9m3UBiFhQk4tKZFk2yEf179rAF/wmMKRoDt81P7AwQoHRb4g5Y vzxUI+w8NCphm3AzCilM1yoGnZXHE95zmBOCanBEHP6Rzf/869+VPOQA90rQQ0U4Aing ZCd8UF8Jjj4sEbXcxVlxGSj6MueHH6EKL0yNU196kdOk+MdZgsqHFfpCT+MSPOIOsUuH ULZTToPUd6yccgxvVQDvewrt5GOYL0HwXME+JZbDYjFuka/8kBtswsQyhgF4GwHtg7qU thqlduWqndFl48Crr0FPrUjcRzUwyu55msilMYfGH/L0TQUNd0OGoxxcBG66tAcRKePs 8LXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tldd8hQ2wUn25jo82acAyXTHIBMdYLaXJm4pX84uJh0=; b=cBG8UIlBjhujn/uNFiJQe1yDPY418hlmwqZXNiecQKu/nkOLjth0OqFm8hb8o9VyxD FwIqz/8FS39fnJRijZ60G/XkX4Cw6OvRR7EXPv76xuBJRbA6dq8CMLjhTRbiAvw9xuGp pnB9kE73bBSGfiie6BUo0OsFqNf3I3fV5NHx5nH/Nd0HHlAuYlyr1Y4FhMW7WdSY6kV3 4yIYClrbFyEPeUXL/+Bu2mHGfez1ntT6BAlM7PLXhQfTPoBz7lFYi6OpYkQk60DgzgXT OF3EvlLYA3FP1HZEsfuf3g28KSIU9htpw9e8SX/4we9s0gGDOAFZ4kfOfFmLokV0TmUz gL9A== X-Gm-Message-State: AJIora/MQXB+Xh7PmqsS9DvTvOInVOgsR7Tp1+Z4hUgLSgP/HkjkWuNQ ncBBh4UvGBiygbO/i1AaYeRW4/nfhTk= X-Received: by 2002:a63:9516:0:b0:40c:c3b9:f984 with SMTP id p22-20020a639516000000b0040cc3b9f984mr10062309pgd.116.1656636234559; Thu, 30 Jun 2022 17:43:54 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:6a2e:d91e:28c5:a052]) by smtp.gmail.com with ESMTPSA id z11-20020aa7888b000000b0052516db7123sm14181442pfe.35.2022.06.30.17.43.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 17:43:54 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/2] tools/btmgmt: Fix errors reported by scan-build Date: Thu, 30 Jun 2022 17:43:51 -0700 Message-Id: <20220701004352.2253107-1-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An 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); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- tools/btmgmt.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 3bf2c21c1..ebef3888f 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -2696,7 +2696,6 @@ static void cmd_disconnect(int argc, char **argv) } } - argc -= optind; argv += optind; optind = 0; @@ -2856,8 +2855,6 @@ static void cmd_find_service(int argc, char **argv) } } - argc -= optind; - argv += optind; optind = 0; cp = (void *) buf; @@ -2931,8 +2928,6 @@ static void cmd_find(int argc, char **argv) } } - argc -= optind; - argv += optind; optind = 0; memset(&cp, 0, sizeof(cp)); @@ -2997,8 +2992,6 @@ static void cmd_stop_find(int argc, char **argv) } } - argc -= optind; - argv += optind; optind = 0; memset(&cp, 0, sizeof(cp)); @@ -3258,7 +3251,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) { @@ -3447,8 +3440,6 @@ static void cmd_irks(int argc, char **argv) } } - argc -= optind; - argv += optind; optind = 0; cp->irk_count = cpu_to_le16(count); @@ -4819,8 +4810,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)) { @@ -5241,8 +5235,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)) { -- 2.34.1