diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-01-05 23:42:00 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-01-05 23:42:00 -0800 |
commit | 29fb15152584455590905726cb5a0e26ea26e9eb (patch) | |
tree | 569e053cec17633825c9f7bd8df042c88b0600e3 /git-compat-util.h | |
parent | 946a5aee3e896aa12cb9d4d21079c6e299baad81 (diff) | |
parent | a469a1019352b8efc4bd7003b0bd59eb60fc428c (diff) | |
download | git-29fb15152584455590905726cb5a0e26ea26e9eb.tar.gz |
Merge branch 'jk/error-const-return'
Help compilers' flow analysis by making it more explicit that
error() always returns -1, to reduce false "variable used
uninitialized" warnings. Looks somewhat ugly but not too much.
* jk/error-const-return:
silence some -Wuninitialized false positives
make error()'s constant return value more visible
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 610e6b7ea4..9661bc9f73 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -290,6 +290,17 @@ extern NORETURN void die_errno(const char *err, ...) __attribute__((format (prin extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); +/* + * Let callers be aware of the constant return value; this can help + * gcc with -Wuninitialized analysis. We have to restrict this trick to + * gcc, though, because of the variadic macro and the magic ## comma pasting + * behavior. But since we're only trying to help gcc, anyway, it's OK; other + * compilers will fall back to using the function as usual. + */ +#ifdef __GNUC__ +#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1) +#endif + extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params)); extern void set_error_routine(void (*routine)(const char *err, va_list params)); |