[ibsim patch 18/23] sim_net.c: initialize the pointer sp with NULL for parse_port

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <honli@xxxxxxxxxx>
---
 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;
-- 
2.15.0-rc1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux