Skip to content

Commit

Permalink
argparse: Fix argv index overrun when argc = 0
Browse files Browse the repository at this point in the history
If argc is 0, the index returned by mm_arg_parse may be 1 while it
should ave been 0. This is fixed ensuring that index is never bigger
than argc.

Change-Id: I0cfb7aa29eedc11506fb844234512702fdfdfec8
  • Loading branch information
nbourdau committed Feb 6, 2022
1 parent 79bd0ac commit 5edd52c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/argparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ int mm_arg_parse(const struct mm_arg_parser* parser, int argc, char* argv[])
return early_stop_parsing(parser, r);
}

return index;
return index > argc ? argc : index;
}

/**
Expand Down

0 comments on commit 5edd52c

Please sign in to comment.