Skip to content

Commit

Permalink
parse-options: fix SunCC compiler warning
Browse files Browse the repository at this point in the history
The compiler reports this because show_gitcomp() never actually
returns a value:

    "parse-options.c", line 520: warning: Function has no return
    statement : show_gitcomp

We could shut the compiler up. But instead let's not bury exit() too
deep. Do the same as internal -h handling, return a special error code
and handle the exit() in parse_options() (and other
parse_options_step() callers) instead.

Reported-by: Ævar Arnfjörð Bjarmason <[email protected]>
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pclouds authored and gitster committed Dec 12, 2018
1 parent 6da2d95 commit a92ec7e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
case PARSE_OPT_HELP:
case PARSE_OPT_ERROR:
exit(129);
case PARSE_OPT_COMPLETE:
exit(0);
case PARSE_OPT_DONE:
if (ctx.argv[0])
dashdash_pos = ctx.cpidx;
Expand Down
2 changes: 2 additions & 0 deletions builtin/shortlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
case PARSE_OPT_HELP:
case PARSE_OPT_ERROR:
exit(129);
case PARSE_OPT_COMPLETE:
exit(0);
case PARSE_OPT_DONE:
goto parse_done;
}
Expand Down
2 changes: 2 additions & 0 deletions builtin/update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
case PARSE_OPT_HELP:
case PARSE_OPT_ERROR:
exit(129);
case PARSE_OPT_COMPLETE:
exit(0);
case PARSE_OPT_NON_OPTION:
case PARSE_OPT_DONE:
{
Expand Down
4 changes: 3 additions & 1 deletion parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
show_negated_gitcomp(original_opts, -1);
show_negated_gitcomp(original_opts, nr_noopts);
fputc('\n', stdout);
exit(0);
return PARSE_OPT_COMPLETE;
}

static int usage_with_options_internal(struct parse_opt_ctx_t *,
Expand Down Expand Up @@ -638,6 +638,8 @@ int parse_options(int argc, const char **argv, const char *prefix,
case PARSE_OPT_HELP:
case PARSE_OPT_ERROR:
exit(129);
case PARSE_OPT_COMPLETE:
exit(0);
case PARSE_OPT_NON_OPTION:
case PARSE_OPT_DONE:
break;
Expand Down
1 change: 1 addition & 0 deletions parse-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ extern int opterror(const struct option *opt, const char *reason, int flags);
/*----- incremental advanced APIs -----*/

enum {
PARSE_OPT_COMPLETE = -2,
PARSE_OPT_HELP = -1,
PARSE_OPT_DONE,
PARSE_OPT_NON_OPTION,
Expand Down

0 comments on commit a92ec7e

Please sign in to comment.