diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-06-13 22:26:59 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-06-13 22:26:59 +0200 |
commit | 7a190a215dbcf782c33ed531104389de8504e29d (patch) | |
tree | 05b00d7adb3abb89de530834599a5daa04a6d026 /usage.c | |
parent | Merge branch 'sb/checkout-recurse-submodules' into maint (diff) | |
parent | usage: add NORETURN to BUG() function definitions (diff) | |
download | git-7a190a215dbcf782c33ed531104389de8504e29d.tar.xz git-7a190a215dbcf782c33ed531104389de8504e29d.zip |
Merge branch 'jk/bug-to-abort' into maint
Introduce the BUG() macro to improve die("BUG: ...").
* jk/bug-to-abort:
usage: add NORETURN to BUG() function definitions
config: complain about --local outside of a git repo
setup_git_env: convert die("BUG") to BUG()
usage.c: add BUG() function
Diffstat (limited to 'usage.c')
-rw-r--r-- | usage.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -201,3 +201,35 @@ void warning(const char *warn, ...) warn_routine(warn, params); va_end(params); } + +static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_list params) +{ + char prefix[256]; + + /* truncation via snprintf is OK here */ + if (file) + snprintf(prefix, sizeof(prefix), "BUG: %s:%d: ", file, line); + else + snprintf(prefix, sizeof(prefix), "BUG: "); + + vreportf(prefix, fmt, params); + abort(); +} + +#ifdef HAVE_VARIADIC_MACROS +NORETURN void BUG_fl(const char *file, int line, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + BUG_vfl(file, line, fmt, ap); + va_end(ap); +} +#else +NORETURN void BUG(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + BUG_vfl(NULL, 0, fmt, ap); + va_end(ap); +} +#endif |