Add a guarded abort() for the problem in PR bin/7059 (no fix so far,

this is hairy).

Reformat this file to comply to style(9). It had mixed styles before.

PR:		bin/7059
This commit is contained in:
Martin Cracauer 1999-04-12 14:23:36 +00:00
parent 7a19b7ed76
commit 9d5efc1507
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=45618

View file

@ -39,7 +39,7 @@
static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95"; static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
#endif #endif
static const char rcsid[] = static const char rcsid[] =
"$Id: memalloc.c,v 1.11 1998/09/10 14:51:06 cracauer Exp $"; "$Id: memalloc.c,v 1.12 1998/09/13 19:24:57 tegge Exp $";
#endif /* not lint */ #endif /* not lint */
#include "shell.h" #include "shell.h"
@ -77,7 +77,6 @@ ckrealloc(p, nbytes)
pointer p; pointer p;
int nbytes; int nbytes;
{ {
if ((p = realloc(p, nbytes)) == NULL) if ((p = realloc(p, nbytes)) == NULL)
error("Out of space"); error("Out of space");
return p; return p;
@ -141,7 +140,8 @@ stalloc(nbytes)
if (blocksize < MINSIZE) if (blocksize < MINSIZE)
blocksize = MINSIZE; blocksize = MINSIZE;
INTOFF; INTOFF;
sp = ckmalloc(sizeof(struct stack_block) - MINSIZE + blocksize); sp = ckmalloc(sizeof(struct stack_block) - MINSIZE +
blocksize);
sp->prev = stackp; sp->prev = stackp;
stacknxt = sp->space; stacknxt = sp->space;
stacknleft = blocksize; stacknleft = blocksize;
@ -187,6 +187,10 @@ popstackmark(mark)
INTOFF; INTOFF;
while (stackp != mark->stackp) { while (stackp != mark->stackp) {
if (stackp == NULL) {
write(2, "Oops, stackp deleted\n", 21);
abort();
}
sp = stackp; sp = stackp;
stackp = sp->prev; stackp = sp->prev;
ckfree(sp); ckfree(sp);
@ -208,18 +212,24 @@ popstackmark(mark)
*/ */
void void
growstackblock() { growstackblock()
{
char *p; char *p;
int newlen = ALIGN(stacknleft * 2 + 100); int newlen;
char *oldspace = stacknxt; char *oldspace;
int oldlen = stacknleft; int oldlen;
struct stack_block *sp; struct stack_block *sp;
newlen = ALIGN(stacknleft * 2 + 100);
oldspace = stacknxt;
oldlen = stacknleft;
if (stacknxt == stackp->space && stackp != &stackbase) { if (stacknxt == stackp->space && stackp != &stackbase) {
INTOFF; INTOFF;
sp = stackp; sp = stackp;
stackp = sp->prev; stackp = sp->prev;
sp = ckrealloc((pointer)sp, sizeof(struct stack_block) - MINSIZE + newlen); sp = ckrealloc((pointer)sp, sizeof(struct stack_block) -
MINSIZE + newlen);
sp->prev = stackp; sp->prev = stackp;
stackp = sp; stackp = sp;
stacknxt = sp->space; stacknxt = sp->space;
@ -266,8 +276,11 @@ grabstackblock(len)
char * char *
growstackstr() { growstackstr()
int len = stackblocksize(); {
int len;
len = stackblocksize();
if (herefd >= 0 && len >= 1024) { if (herefd >= 0 && len >= 1024) {
xwrite(herefd, stackblock(), len); xwrite(herefd, stackblock(), len);
sstrnleft = len - 1; sstrnleft = len - 1;
@ -284,8 +297,11 @@ growstackstr() {
*/ */
char * char *
makestrspace() { makestrspace()
int len = stackblocksize() - sstrnleft; {
int len;
len = stackblocksize() - sstrnleft;
growstackblock(); growstackblock();
sstrnleft = stackblocksize() - len; sstrnleft = stackblocksize() - len;
return stackblock() + len; return stackblock() + len;