comparison src/emacs.c @ 19354:85ac99b8b5c8

(main): Update re_max_failures so regex.c won't overflow the stack, except when dumping.
author Richard M. Stallman <rms@gnu.org>
date Fri, 15 Aug 1997 05:07:01 +0000
parents bc1937e6cea5
children fce71d3f95b1
comparison
equal deleted inserted replaced
19353:885b89f866b4 19354:85ac99b8b5c8
577 #endif /* SHARABLE_LIB_BUG */ 577 #endif /* SHARABLE_LIB_BUG */
578 #endif /* LINK_CRTL_SHARE */ 578 #endif /* LINK_CRTL_SHARE */
579 #endif /* VMS */ 579 #endif /* VMS */
580 580
581 #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK) 581 #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK)
582 /* Extend the stack space available. */ 582 /* Extend the stack space available.
583 if (!getrlimit (RLIMIT_STACK, &rlim)) 583 Don't do that if dumping, since some systems (e.g. DJGPP)
584 might define a smaller stack limit at that time. */
585 if (1
586 #ifndef CANNOT_DUMP
587 && (!noninteractive || initialized)
588 #endif
589 && !getrlimit (RLIMIT_STACK, &rlim))
584 { 590 {
585 long newlim; 591 long newlim;
592 extern int re_max_failures;
586 /* Approximate the amount regex.c needs, plus some more. */ 593 /* Approximate the amount regex.c needs, plus some more. */
587 newlim = 800000 * sizeof (char *); 594 newlim = re_max_failures * 2 * 20 * sizeof (char *);
588 #ifdef __NetBSD__ 595 #ifdef __NetBSD__
589 /* NetBSD (at least NetBSD 1.2G and former) has a bug in its 596 /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
590 stack allocation routine for new process that the allocation 597 stack allocation routine for new process that the allocation
591 fails if stack limit is not on page boundary. So, round up the 598 fails if stack limit is not on page boundary. So, round up the
592 new limit to page boundary. */ 599 new limit to page boundary. */
593 newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize(); 600 newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize();
594 #endif 601 #endif
595 if (newlim > rlim.rlim_max) 602 if (newlim > rlim.rlim_max)
596 newlim = rlim.rlim_max; 603 {
604 newlim = rlim.rlim_max;
605 /* Don't let regex.c overflow the stack. */
606 re_max_failures = newlim / (2 * 20 * sizeof (char *));
607 }
597 if (rlim.rlim_cur < newlim) 608 if (rlim.rlim_cur < newlim)
598 rlim.rlim_cur = newlim; 609 rlim.rlim_cur = newlim;
599 610
600 setrlimit (RLIMIT_STACK, &rlim); 611 setrlimit (RLIMIT_STACK, &rlim);
601 } 612 }