]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix emacs_re_safe_alloca calculation
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 3 Oct 2018 22:55:43 +0000 (15:55 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 3 Oct 2018 22:57:26 +0000 (15:57 -0700)
Problem and draft fix noted by Eli Zaretskii in:
https://lists.gnu.org/r/emacs-devel/2018-10/msg00022.html
* src/emacs.c (main): Fix arithmetic used in calculation
of emacs_re_safe_alloca.

src/emacs.c

index b1c96d18285a267a5c90b44fdf7594fcc1fc3935..ddaaf3fed51d36eb20f23d684271240bd7cd7fbc 100644 (file)
@@ -888,11 +888,11 @@ main (int argc, char **argv)
                lim = newlim;
            }
        }
-      /* If the stack is big enough, let regex-emacs.c more of it before
-         falling back to heap allocation.  */
-      emacs_re_safe_alloca = max
-        (min (lim - extra, SIZE_MAX) * (min_ratio / ratio),
-         MAX_ALLOCA);
+      /* If the stack is big enough, let regex-emacs.c use more of it
+        before falling back to heap allocation.  */
+      ptrdiff_t max_failures
+       = min (lim - extra, min (PTRDIFF_MAX, SIZE_MAX)) / ratio;
+      emacs_re_safe_alloca = max (max_failures * min_ratio, MAX_ALLOCA);
     }
 #endif /* HAVE_SETRLIMIT and RLIMIT_STACK and not CYGWIN */