From patchwork Wed Jan 2 13:13:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10746357 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6BF3746 for ; Wed, 2 Jan 2019 13:14:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 962BE28848 for ; Wed, 2 Jan 2019 13:14:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AE6D28857; Wed, 2 Jan 2019 13:14:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D199228848 for ; Wed, 2 Jan 2019 13:14:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729918AbfABNOs (ORCPT ); Wed, 2 Jan 2019 08:14:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55880 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729901AbfABNOs (ORCPT ); Wed, 2 Jan 2019 08:14:48 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9460C0828C7; Wed, 2 Jan 2019 13:14:47 +0000 (UTC) Received: from localhost (ovpn-12-97.pek2.redhat.com [10.72.12.97]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E3F6760C67; Wed, 2 Jan 2019 13:14:46 +0000 (UTC) From: Honggang Li To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [ibsim patch 18/23] sim_net.c: initialize the pointer sp with NULL for parse_port Date: Wed, 2 Jan 2019 21:13:13 +0800 Message-Id: <20190102131318.5765-18-honli@redhat.com> In-Reply-To: <20190102131318.5765-1-honli@redhat.com> References: <20190102131318.5765-1-honli@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 02 Jan 2019 13:14:47 +0000 (UTC) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP These two issues were detected by Coverity. Error: CLANG_WARNING: [#def6] ibsim-0.7/ibsim/sim_net.c:786:2: warning: 7th function call argument is an uninitialized value // PDEBUG("remotenodeid %s s %s sp %s", remotenodeid, s, sp); // ^ ibsim-0.7/ibsim/sim_net.c:56:32: note: expanded from macro 'PDEBUG' //#define PDEBUG if (parsedebug) IBWARN // ^ /usr/include/infiniband/mad.h:1716:26: note: expanded from macro 'IBWARN' //#define IBWARN(fmt, ...) fprintf(stderr, "ibwarn: [%d] %s: " fmt "\n", \ // ^ ibsim-0.7/ibsim/sim_net.c:741:33: note: 'sp' declared without an initial value // char remotenodeid[NODEIDLEN], *sp; // ^~ ibsim-0.7/ibsim/sim_net.c:746:6: note: Assuming the condition is false // if (line[0] == '@') { // ^~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:746:2: note: Taking false branch // if (line[0] == '@') { // ^ ibsim-0.7/ibsim/sim_net.c:753:6: note: Assuming 'portnum' is >= 0 // if (portnum < 0 || portnum > maxports) { // ^~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:753:6: note: Left side of '||' is false ibsim-0.7/ibsim/sim_net.c:753:21: note: Assuming 'portnum' is <= 'maxports' // if (portnum < 0 || portnum > maxports) { // ^~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:753:2: note: Taking false branch // if (portnum < 0 || portnum > maxports) { // ^ ibsim-0.7/ibsim/sim_net.c:757:6: note: Assuming 'portnum' is not equal to 0 // if (!portnum && line[1] != 0) { // ^~~~~~~~ ibsim-0.7/ibsim/sim_net.c:757:15: note: Left side of '&&' is false // if (!portnum && line[1] != 0) { // ^ ibsim-0.7/ibsim/sim_net.c:764:6: note: Assuming 'type' is equal to SWITCH_NODE // if (type != SWITCH_NODE && !portnum) { // ^~~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:764:26: note: Left side of '&&' is false // if (type != SWITCH_NODE && !portnum) { // ^ ibsim-0.7/ibsim/sim_net.c:769:2: note: Taking false branch // if (!(s = parse_node_id(line, NULL))) { // ^ ibsim-0.7/ibsim/sim_net.c:774:2: note: Taking false branch // if (isalias) { // ^ ibsim-0.7/ibsim/sim_net.c:782:6: note: Assuming the condition is false // if (strchr(s, '@')) // ^~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:782:2: note: Taking false branch // if (strchr(s, '@')) // ^ ibsim-0.7/ibsim/sim_net.c:785:2: note: Calling 'expand_name' // expand_name(s, remotenodeid, &sp); // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:683:2: note: Taking false branch // if (!base) // ^ ibsim-0.7/ibsim/sim_net.c:686:6: note: Assuming the condition is false // if (!strchr(base, '@')) { // ^~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:686:2: note: Taking false branch // if (!strchr(base, '@')) { // ^ ibsim-0.7/ibsim/sim_net.c:697:36: note: Assuming the condition is false // snprintf(name, NODEIDLEN, "%s%s", base[0] == '@' ? netprefix : "", base); // ^~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:697:36: note: '?' condition is false ibsim-0.7/ibsim/sim_net.c:698:2: note: Assuming 'parsedebug' is 0 // PDEBUG("alias %s", name); // ^~~~~~ ibsim-0.7/ibsim/sim_net.c:56:20: note: expanded from macro 'PDEBUG' //#define PDEBUG if (parsedebug) IBWARN // ^~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:698:2: note: Taking false branch ibsim-0.7/ibsim/sim_net.c:56:16: note: expanded from macro 'PDEBUG' //#define PDEBUG if (parsedebug) IBWARN // ^ ibsim-0.7/ibsim/sim_net.c:700:8: note: Assuming 's' is null // if (!(s = map_alias(name))) // ^ ibsim-0.7/ibsim/sim_net.c:700:2: note: Taking true branch // if (!(s = map_alias(name))) // ^ ibsim-0.7/ibsim/sim_net.c:701:3: note: Returning without writing to '*portstr' // return NULL; // ^ ibsim-0.7/ibsim/sim_net.c:785:2: note: Returning from 'expand_name' // expand_name(s, remotenodeid, &sp); // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:786:2: note: Assuming 'parsedebug' is not equal to 0 // PDEBUG("remotenodeid %s s %s sp %s", remotenodeid, s, sp); // ^~~~~~ ibsim-0.7/ibsim/sim_net.c:56:20: note: expanded from macro 'PDEBUG' //#define PDEBUG if (parsedebug) IBWARN // ^~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:786:2: note: Taking true branch ibsim-0.7/ibsim/sim_net.c:56:16: note: expanded from macro 'PDEBUG' //#define PDEBUG if (parsedebug) IBWARN // ^ ibsim-0.7/ibsim/sim_net.c:786:2: note: 7th function call argument is an uninitialized value // PDEBUG("remotenodeid %s s %s sp %s", remotenodeid, s, sp); // ^ ~~ ibsim-0.7/ibsim/sim_net.c:56:32: note: expanded from macro 'PDEBUG' //#define PDEBUG if (parsedebug) IBWARN // ^ /usr/include/infiniband/mad.h:1716:26: note: expanded from macro 'IBWARN' //#define IBWARN(fmt, ...) fprintf(stderr, "ibwarn: [%d] %s: " fmt "\n", \ // ^ // 784| // 785| expand_name(s, remotenodeid, &sp); // 786|-> PDEBUG("remotenodeid %s s %s sp %s", remotenodeid, s, sp); // 787| // 788| s += strlen(s) + 1; Error: CLANG_WARNING: [#def7] ibsim-0.7/ibsim/sim_net.c:789:6: warning: Branch condition evaluates to a garbage value // if (!sp && *s == '[') // ^~~ ibsim-0.7/ibsim/sim_net.c:741:33: note: 'sp' declared without an initial value // char remotenodeid[NODEIDLEN], *sp; // ^~ ibsim-0.7/ibsim/sim_net.c:746:6: note: Assuming the condition is false // if (line[0] == '@') { // ^~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:746:2: note: Taking false branch // if (line[0] == '@') { // ^ ibsim-0.7/ibsim/sim_net.c:753:6: note: Assuming 'portnum' is >= 0 // if (portnum < 0 || portnum > maxports) { // ^~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:753:6: note: Left side of '||' is false ibsim-0.7/ibsim/sim_net.c:753:21: note: Assuming 'portnum' is <= 'maxports' // if (portnum < 0 || portnum > maxports) { // ^~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:753:2: note: Taking false branch // if (portnum < 0 || portnum > maxports) { // ^ ibsim-0.7/ibsim/sim_net.c:757:6: note: Assuming 'portnum' is not equal to 0 // if (!portnum && line[1] != 0) { // ^~~~~~~~ ibsim-0.7/ibsim/sim_net.c:757:15: note: Left side of '&&' is false // if (!portnum && line[1] != 0) { // ^ ibsim-0.7/ibsim/sim_net.c:764:6: note: Assuming 'type' is equal to SWITCH_NODE // if (type != SWITCH_NODE && !portnum) { // ^~~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:764:26: note: Left side of '&&' is false // if (type != SWITCH_NODE && !portnum) { // ^ ibsim-0.7/ibsim/sim_net.c:769:2: note: Taking false branch // if (!(s = parse_node_id(line, NULL))) { // ^ ibsim-0.7/ibsim/sim_net.c:774:2: note: Taking false branch // if (isalias) { // ^ ibsim-0.7/ibsim/sim_net.c:782:6: note: Assuming the condition is false // if (strchr(s, '@')) // ^~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:782:2: note: Taking false branch // if (strchr(s, '@')) // ^ ibsim-0.7/ibsim/sim_net.c:785:2: note: Calling 'expand_name' // expand_name(s, remotenodeid, &sp); // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:683:2: note: Taking false branch // if (!base) // ^ ibsim-0.7/ibsim/sim_net.c:686:6: note: Assuming the condition is false // if (!strchr(base, '@')) { // ^~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:686:2: note: Taking false branch // if (!strchr(base, '@')) { // ^ ibsim-0.7/ibsim/sim_net.c:697:36: note: Assuming the condition is false // snprintf(name, NODEIDLEN, "%s%s", base[0] == '@' ? netprefix : "", base); // ^~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:697:36: note: '?' condition is false ibsim-0.7/ibsim/sim_net.c:698:2: note: Assuming 'parsedebug' is 0 // PDEBUG("alias %s", name); // ^~~~~~ ibsim-0.7/ibsim/sim_net.c:56:20: note: expanded from macro 'PDEBUG' //#define PDEBUG if (parsedebug) IBWARN // ^~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:698:2: note: Taking false branch ibsim-0.7/ibsim/sim_net.c:56:16: note: expanded from macro 'PDEBUG' //#define PDEBUG if (parsedebug) IBWARN // ^ ibsim-0.7/ibsim/sim_net.c:700:8: note: Assuming 's' is null // if (!(s = map_alias(name))) // ^ ibsim-0.7/ibsim/sim_net.c:700:2: note: Taking true branch // if (!(s = map_alias(name))) // ^ ibsim-0.7/ibsim/sim_net.c:701:3: note: Returning without writing to '*portstr' // return NULL; // ^ ibsim-0.7/ibsim/sim_net.c:785:2: note: Returning from 'expand_name' // expand_name(s, remotenodeid, &sp); // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ibsim-0.7/ibsim/sim_net.c:789:6: note: Branch condition evaluates to a garbage value // if (!sp && *s == '[') // ^~~ // 787| // 788| s += strlen(s) + 1; // 789|-> if (!sp && *s == '[') // 790| sp = s + 1; // 791| Signed-off-by: Honggang Li --- ibsim/sim_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibsim/sim_net.c b/ibsim/sim_net.c index 8f285e6d8f1a..bdce93a6ac10 100644 --- a/ibsim/sim_net.c +++ b/ibsim/sim_net.c @@ -738,7 +738,7 @@ static int new_alias(char *alias, Node * node, int portnum) static int parse_port(char *line, Node * node, int type, int maxports) { - char remotenodeid[NODEIDLEN], *sp; + char remotenodeid[NODEIDLEN], *sp = NULL; int portnum, isalias = 0; Port *port; char *s;