Skip to content

Commit a469a10

Browse files
peffgitster
authored andcommitted
silence some -Wuninitialized false positives
There are a few error functions that simply wrap error() and provide a standardized message text. Like error(), they always return -1; knowing that can help the compiler silence some false positive -Wuninitialized warnings. One strategy would be to just declare these as inline in the header file so that the compiler can see that they always return -1. However, gcc does not always inline them (e.g., it will not inline opterror, even with -O3), which renders our change pointless. Instead, let's follow the same route we did with error() in the last patch, and define a macro that makes the constant return value obvious to the compiler. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e208f9c commit a469a10

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,9 @@ extern int check_repository_format_version(const char *var, const char *value, v
11361136
extern int git_env_bool(const char *, int);
11371137
extern int git_config_system(void);
11381138
extern int config_error_nonbool(const char *);
1139+
#ifdef __GNUC__
1140+
#define config_error_nonbool(s) (config_error_nonbool(s), -1)
1141+
#endif
11391142
extern const char *get_log_output_encoding(void);
11401143
extern const char *get_commit_output_encoding(void);
11411144

config.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
16601660
* Call this to report error for your variable that should not
16611661
* get a boolean value (i.e. "[my] var" means "true").
16621662
*/
1663+
#undef config_error_nonbool
16631664
int config_error_nonbool(const char *var)
16641665
{
16651666
return error("Missing value for '%s'", var);

parse-options.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ int optbug(const struct option *opt, const char *reason)
1818
return error("BUG: switch '%c' %s", opt->short_name, reason);
1919
}
2020

21-
int opterror(const struct option *opt, const char *reason, int flags)
22-
{
23-
if (flags & OPT_SHORT)
24-
return error("switch `%c' %s", opt->short_name, reason);
25-
if (flags & OPT_UNSET)
26-
return error("option `no-%s' %s", opt->long_name, reason);
27-
return error("option `%s' %s", opt->long_name, reason);
28-
}
29-
3021
static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
3122
int flags, const char **arg)
3223
{
@@ -594,3 +585,12 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
594585
return usage_with_options_internal(ctx, usagestr, opts, 0, err);
595586
}
596587

588+
#undef opterror
589+
int opterror(const struct option *opt, const char *reason, int flags)
590+
{
591+
if (flags & OPT_SHORT)
592+
return error("switch `%c' %s", opt->short_name, reason);
593+
if (flags & OPT_UNSET)
594+
return error("option `no-%s' %s", opt->long_name, reason);
595+
return error("option `%s' %s", opt->long_name, reason);
596+
}

parse-options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ extern NORETURN void usage_msg_opt(const char *msg,
177177

178178
extern int optbug(const struct option *opt, const char *reason);
179179
extern int opterror(const struct option *opt, const char *reason, int flags);
180+
#ifdef __GNUC__
181+
#define opterror(o,r,f) (opterror((o),(r),(f)), -1)
182+
#endif
183+
180184
/*----- incremental advanced APIs -----*/
181185

182186
enum {

0 commit comments

Comments
 (0)