Skip to content

Commit ce7d759

Browse files
committed
mctp-client: fix valid_parse usage
We have a potentially uninit variable here: ../src/mctp-client.c: In function ‘main’: ../src/mctp-client.c:212:14: warning: ‘valid_parse’ may be used uninitialized [-Wmaybe-uninitialized] 212 | bool valid_parse, valid_eid, valid_type; | ^~~~~~~~~~~ The valid_parse variable is only initialised in the argument iterator, so checking outside of this loop may miss cases where a subsequent argument resets it. Instead, error-out in the same iteration as an invalid parse. Signed-off-by: Jeremy Kerr <[email protected]>
1 parent 6caf08c commit ce7d759

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/mctp-client.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ static int find_data(int argc, char **argv)
209209

210210
int main(int argc, char **argv)
211211
{
212-
bool valid_parse, valid_eid, valid_type;
213212
int ctr, data_idx, net = MCTP_NET_ANY;
213+
bool valid_eid, valid_type;
214214
struct data_t send_data;
215215
char *tag, *endp, *val;
216216
unsigned long int tmp;
@@ -235,6 +235,8 @@ int main(int argc, char **argv)
235235
valid_type = false;
236236

237237
for (ctr = 1; ctr < argc; ctr += 2) {
238+
bool valid_parse;
239+
238240
tag = argv[ctr];
239241
val = argv[ctr + 1];
240242
tmp = strtoul(val, &endp, 0);
@@ -257,9 +259,12 @@ int main(int argc, char **argv)
257259
valid_type = true;
258260
} else
259261
errx(EXIT_FAILURE, "invalid tag: %s", tag);
262+
263+
if (!valid_parse)
264+
errx(EXIT_FAILURE, "invalid argument: %s", val);
260265
}
261266

262-
if (!valid_parse || !valid_eid || !valid_type) {
267+
if (!valid_eid || !valid_type) {
263268
print_usage();
264269
return EXIT_FAILURE;
265270
}

0 commit comments

Comments
 (0)