diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-03-27 17:50:56 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-03-27 17:50:56 +0000 |
commit | e9a81ff478e726ad486d829d3d55bd84072634f8 (patch) | |
tree | f11d28163de84dd5e5992e8276d28059843490ed | |
parent | 0c0c73a5468d39e33dc965086ae7d304f5fd40cc (diff) |
Make call stack auto-growing, instead of fixed size. Enables much deeper
recursion.
-rw-r--r-- | usr.bin/dc/bcode.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c index ebec9f34361..e57f2ec9b95 100644 --- a/usr.bin/dc/bcode.c +++ b/usr.bin/dc/bcode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bcode.c,v 1.26 2004/12/01 08:40:12 otto Exp $ */ +/* $OpenBSD: bcode.c,v 1.27 2005/03/27 17:50:55 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -17,7 +17,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: bcode.c,v 1.26 2004/12/01 08:40:12 otto Exp $"; +static const char rcsid[] = "$OpenBSD: bcode.c,v 1.27 2005/03/27 17:50:55 otto Exp $"; #endif /* not lint */ #include <ssl/ssl.h> @@ -35,7 +35,7 @@ BIGNUM zero; /* #define DEBUGGING */ #define MAX_ARRAY_INDEX 2048 -#define RECURSION_STACK_SIZE 100 +#define READSTACK_SIZE 8 #define NO_ELSE -2 /* -1 is EOF */ #define REG_ARRAY_SIZE_SMALL (UCHAR_MAX + 1) @@ -46,12 +46,13 @@ struct bmachine { u_int scale; u_int obase; u_int ibase; - int readsp; + size_t readsp; bool extended_regs; size_t reg_array_size; struct stack *reg; volatile sig_atomic_t interrupted; - struct source readstack[RECURSION_STACK_SIZE]; + struct source *readstack; + size_t readstack_sz; }; static struct bmachine bmachine; @@ -253,6 +254,11 @@ init_bmachine(bool extended_registers) for (i = 0; i < bmachine.reg_array_size; i++) stack_init(&bmachine.reg[i]); + bmachine.readstack_sz = READSTACK_SIZE; + bmachine.readstack = malloc(sizeof(struct source) * + bmachine.readstack_sz); + if (bmachine.readstack == NULL) + err(1, NULL); bmachine.obase = bmachine.ibase = 10; BN_init(&zero); bn_check(BN_zero(&zero)); @@ -1661,8 +1667,16 @@ eval_string(char *p) } else unreadch(); } - if (bmachine.readsp == RECURSION_STACK_SIZE-1) - errx(1, "recursion too deep"); + if (bmachine.readsp == bmachine.readstack_sz - 1) { + size_t newsz = bmachine.readstack_sz * 2; + struct source *stack; + stack = realloc(bmachine.readstack, newsz * + sizeof(struct source)); + if (stack == NULL) + err(1, "recursion too deep"); + bmachine.readstack_sz = newsz; + bmachine.readstack = stack; + } src_setstring(&bmachine.readstack[++bmachine.readsp], p); } |