]> git.neil.brown.name Git - git.git/blobdiff - usage.c
Git 2.14-rc0
[git.git] / usage.c
diff --git a/usage.c b/usage.c
index 2f87ca69a8299485ee013187f99ffbdb2618d7c8..1ea7df9a202339972ee59f35a5ba8852502c915f 100644 (file)
--- a/usage.c
+++ b/usage.c
@@ -44,7 +44,23 @@ static void warn_builtin(const char *warn, va_list params)
 static int die_is_recursing_builtin(void)
 {
        static int dying;
-       return dying++;
+       /*
+        * Just an arbitrary number X where "a < x < b" where "a" is
+        * "maximum number of pthreads we'll ever plausibly spawn" and
+        * "b" is "something less than Inf", since the point is to
+        * prevent infinite recursion.
+        */
+       static const int recursion_limit = 1024;
+
+       dying++;
+       if (dying > recursion_limit) {
+               return 1;
+       } else if (dying == 2) {
+               warning("die() called many times. Recursion error or racy threaded death!");
+               return 0;
+       } else {
+               return 0;
+       }
 }
 
 /* If we are in a dlopen()ed .so write to a global variable would segfault