lim = newlim;
}
}
- /* If the stack is big enough, let regex.c more of it before
- falling back to heap allocation. */
+ /* If the stack is big enough, let regex-emacs.c use more of it
+ before falling back to heap allocation. */
+ if (lim < extra)
- lim = extra; /* avoid wrap-around in unsigned subtraction */
- emacs_re_safe_alloca =
- max (min (lim - extra, SIZE_MAX) * (min_ratio / ratio), MAX_ALLOCA);
++ lim = extra; /* avoid wrap-around in unsigned subtraction */
+ 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 */