git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] parse-options: fix segmentation fault when a required value is missing
@ 2008-07-21 18:30 Olivier Marin
  2008-07-21 19:07 ` Pierre Habouzit
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Marin @ 2008-07-21 18:30 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: Junio C Hamano, Git Mailing List

From: Olivier Marin <dkr@freesurf.fr>

p->argc represent the number of arguments that have not been parsed yet,
_including_ the one we are currently parsing. If it is not greater than
one then there is no more argument.

Signed-off-by: Olivier Marin <dkr@freesurf.fr>
---
 I hope this is the right fix.

 parse-options.c          |    2 +-
 t/t0040-parse-options.sh |    7 +++++++
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/parse-options.c b/parse-options.c
index 987b015..71a7acf 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -22,7 +22,7 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
                p->opt = NULL;
        } else if (p->argc == 1 && (opt->flags & PARSE_OPT_LASTARG_DEFAULT)) {
                *arg = (const char *)opt->defval;
-       } else if (p->argc) {
+       } else if (p->argc > 1) {
                p->argc--;
                *arg = *++p->argv;
        } else
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 6309aed..03dbe00 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -78,6 +78,13 @@ test_expect_success 'long options' '
        test_cmp expect output
 '
 
+test_expect_success 'missing required value' '
+       test-parse-options -s;
+       test $? = 129 &&
+       test-parse-options --string;
+       test $? = 129
+'
+
 cat > expect << EOF
 boolean: 1
 integer: 13
-- 
1.6.0.rc0.1.g75f42

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-07-22 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-21 18:30 [PATCH] parse-options: fix segmentation fault when a required value is missing Olivier Marin
2008-07-21 19:07 ` Pierre Habouzit
2008-07-22 10:11   ` [PATCH v2] " Olivier Marin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).