From 5edd52caf2eb3fc16d27c45f45aa57749bf9c467 Mon Sep 17 00:00:00 2001 From: Nicolas Bourdaud Date: Sun, 6 Feb 2022 18:29:21 +0100 Subject: [PATCH] argparse: Fix argv index overrun when argc = 0 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 --- src/argparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/argparse.c b/src/argparse.c index 5d2cd6e..db8a246 100644 --- a/src/argparse.c +++ b/src/argparse.c @@ -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; } /**