Skip to content

Commit 16abe2e

Browse files
committed
Merge pull request #615 from hjelmn/opal_coverity
event/libevent2022: fix coverity issue
2 parents 6b93db6 + f72b6d4 commit 16abe2e

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

opal/mca/crs/none/crs_none_module.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2004-2010 The Trustees of Indiana University.
34
* All rights reserved.
45
*
56
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
7+
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
8+
* reserved.
69
* $COPYRIGHT$
710
*
811
* Additional copyrights may follow
@@ -101,8 +104,7 @@ int opal_crs_none_restart(opal_crs_base_snapshot_t *base_snapshot, bool spawn_ch
101104
opal_output(0,
102105
"crs:none: checkpoint(): Error: Unable to open the file (%s)",
103106
base_snapshot->metadata_filename);
104-
exit_status = OPAL_ERROR;
105-
goto cleanup;
107+
return OPAL_ERROR;
106108
}
107109
}
108110

@@ -131,10 +133,9 @@ int opal_crs_none_restart(opal_crs_base_snapshot_t *base_snapshot, bool spawn_ch
131133
if( !spawn_child ) {
132134
opal_output_verbose(10, opal_crs_base_framework.framework_output,
133135
"crs:none: none_restart: exec :(%s, %s):",
134-
strdup(cr_argv[0]),
135-
opal_argv_join(cr_argv, ' '));
136+
cr_argv[0], tmp_argv[0]);
136137

137-
status = execvp(strdup(cr_argv[0]), cr_argv);
138+
status = execvp(cr_argv[0], cr_argv);
138139

139140
if(status < 0) {
140141
opal_output(opal_crs_base_framework.framework_output,
@@ -152,10 +153,11 @@ int opal_crs_none_restart(opal_crs_base_snapshot_t *base_snapshot, bool spawn_ch
152153
}
153154

154155
cleanup:
155-
if (NULL != base_snapshot->metadata) {
156-
fclose(base_snapshot->metadata);
156+
if (cr_argv) {
157+
opal_argv_free (cr_argv);
157158
}
158-
base_snapshot->metadata = NULL;
159+
160+
fclose(base_snapshot->metadata);
159161

160162
return exit_status;
161163
}

opal/mca/event/libevent2022/libevent2022_component.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static int libevent2022_register (void)
125125
const struct eventop** _eventop = eventops;
126126
char available_eventops[1024] = "none";
127127
char *help_msg = NULL;
128-
int ret, len = 1024;
128+
int ret;
129129

130130
/* Retrieve the upper level specified event system, if any.
131131
* Default to select() on OS X and poll() everywhere else because
@@ -153,17 +153,15 @@ static int libevent2022_register (void)
153153
*/
154154

155155
if (NULL != (*_eventop)) {
156-
available_eventops[0] = '\0';
157-
}
156+
const int len = sizeof (available_eventops);
157+
int cur_len = snprintf (available_eventops, len, "%s", (*(_eventop++))->name);
158158

159-
while( NULL != (*_eventop) ) {
160-
if( available_eventops[0] != '\0' ) {
161-
(void) strncat (available_eventops, ", ", len);
159+
for (int i = 1 ; eventops[i] && cur_len < len ; ++i) {
160+
cur_len += snprintf (available_eventops + cur_len, len - cur_len, ", %s",
161+
eventops[i]->name);
162162
}
163-
(void) strncat (available_eventops, (*_eventop)->name,
164-
len);
165-
_eventop++; /* go to the next available eventop */
166-
len = 1024 - strlen(available_eventops);
163+
/* ensure the available_eventops string is always NULL-terminated */
164+
available_eventops[len - 1] = '\0';
167165
}
168166

169167
#ifdef __APPLE__

0 commit comments

Comments
 (0)