aboutsummaryrefslogtreecommitdiffstats
path: root/usage.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-06-10 15:04:15 -0700
committerJunio C Hamano <gitster@pobox.com>2022-06-10 15:04:15 -0700
commit4da14b574f2e52eb05e4fef7ed169a8f9e3a8b67 (patch)
tree134a132278b3ca34974f2812b24acb5fe9a47810 /usage.c
parentMerge branch 'jy/gitweb-xhtml5' (diff)
parentcache-tree.c: use bug() and BUG_if_bug() (diff)
downloadgit-4da14b574f2e52eb05e4fef7ed169a8f9e3a8b67.tar.gz
git-4da14b574f2e52eb05e4fef7ed169a8f9e3a8b67.zip
Merge branch 'ab/bug-if-bug'
A new bug() and BUG_if_bug() API is introduced to make it easier to uniformly log "detect multiple bugs and abort in the end" pattern. * ab/bug-if-bug: cache-tree.c: use bug() and BUG_if_bug() receive-pack: use bug() and BUG_if_bug() parse-options.c: use optbug() instead of BUG() "opts" check parse-options.c: use new bug() API for optbug() usage.c: add a non-fatal bug() function to go with BUG() common-main.c: move non-trace2 exit() behavior out of trace2.c
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/usage.c b/usage.c
index b738dd178b..79900d0287 100644
--- a/usage.c
+++ b/usage.c
@@ -290,18 +290,24 @@ void warning(const char *warn, ...)
/* Only set this, ever, from t/helper/, when verifying that bugs are caught. */
int BUG_exit_code;
-static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_list params)
+static void BUG_vfl_common(const char *file, int line, const char *fmt,
+ va_list params)
{
char prefix[256];
- va_list params_copy;
- static int in_bug;
-
- va_copy(params_copy, params);
/* truncation via snprintf is OK here */
snprintf(prefix, sizeof(prefix), "BUG: %s:%d: ", file, line);
vreportf(prefix, fmt, params);
+}
+
+static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_list params)
+{
+ va_list params_copy;
+ static int in_bug;
+
+ va_copy(params_copy, params);
+ BUG_vfl_common(file, line, fmt, params);
if (in_bug)
abort();
@@ -317,11 +323,28 @@ static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_lis
NORETURN void BUG_fl(const char *file, int line, const char *fmt, ...)
{
va_list ap;
+
+ bug_called_must_BUG = 0;
+
va_start(ap, fmt);
BUG_vfl(file, line, fmt, ap);
va_end(ap);
}
+int bug_called_must_BUG;
+void bug_fl(const char *file, int line, const char *fmt, ...)
+{
+ va_list ap, cp;
+
+ bug_called_must_BUG = 1;
+
+ va_copy(cp, ap);
+ va_start(ap, fmt);
+ BUG_vfl_common(file, line, fmt, ap);
+ va_end(ap);
+ trace2_cmd_error_va(fmt, cp);
+}
+
#ifdef SUPPRESS_ANNOTATED_LEAKS
void unleak_memory(const void *ptr, size_t len)
{