summaryrefslogtreecommitdiffstats
path: root/usr.bin/yacc
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2001-10-05 02:09:43 +0000
committerobrien <obrien@FreeBSD.org>2001-10-05 02:09:43 +0000
commit1547f1d07f68f23f3a62a40397b800fe8fbf0629 (patch)
tree1f2ac219871086c60ad4e8c295e7373041efc1a8 /usr.bin/yacc
parent7d2463e9d1f6b0d1b2fbf51b582dda8d1731154d (diff)
downloadFreeBSD-src-1547f1d07f68f23f3a62a40397b800fe8fbf0629.zip
FreeBSD-src-1547f1d07f68f23f3a62a40397b800fe8fbf0629.tar.gz
Fix the output so it really does dynamically resize the table.
Submitted by: Diane Bruce <db@db.net>
Diffstat (limited to 'usr.bin/yacc')
-rw-r--r--usr.bin/yacc/output.c58
1 files changed, 44 insertions, 14 deletions
diff --git a/usr.bin/yacc/output.c b/usr.bin/yacc/output.c
index 2390a94..8226fdb 100644
--- a/usr.bin/yacc/output.c
+++ b/usr.bin/yacc/output.c
@@ -69,6 +69,7 @@ static int pack_vector __P((int));
static void save_column __P((int, int));
static void sort_actions __P((void));
static void token_actions __P((void));
+static int increase_maxtable __P((int));
static const char line_format[] = "#line %d \"%s\"\n";
static int nvectors;
@@ -630,7 +631,6 @@ int vector;
register int ok;
register short *from;
register short *to;
- int newmax;
i = order[vector];
t = tally[i];
@@ -655,19 +655,7 @@ int vector;
{
if (loc >= MAXTABLE)
fatal("maximum table size exceeded");
-
- newmax = maxtable;
- do { newmax += 200; } while (newmax <= loc);
- table = (short *) REALLOC(table, newmax*sizeof(short));
- if (table == 0) no_space();
- check = (short *) REALLOC(check, newmax*sizeof(short));
- if (check == 0) no_space();
- for (l = maxtable; l < newmax; ++l)
- {
- table[l] = 0;
- check[l] = -1;
- }
- maxtable = newmax;
+ maxtable = increase_maxtable(loc);
}
if (check[loc] != -1)
@@ -689,7 +677,19 @@ int vector;
}
while (check[lowzero] != -1)
+ {
+ if (lowzero >= maxtable)
+ {
+ if (lowzero >= MAXTABLE)
+ {
+ fatal("maximum table size exceeded in check\n");
+ }
+
+ maxtable = increase_maxtable(loc);
+ }
+
++lowzero;
+ }
return (j);
}
@@ -1313,3 +1313,33 @@ free_reductions()
FREE(rp);
}
}
+
+/*
+ * increase_maxtable
+ *
+ * inputs - loc location in table
+ * output - size increased to
+ * side effects - table is increase by at least 200 short words
+ */
+
+int
+increase_maxtable(int loc)
+{
+ int newmax;
+ int l;
+
+ newmax = maxtable;
+
+ do { newmax += 200; } while (newmax <= loc);
+ table = (short *) REALLOC(table, newmax*sizeof(short));
+ if (table == 0) no_space();
+ check = (short *) REALLOC(check, newmax*sizeof(short));
+ if (check == 0) no_space();
+ for (l = maxtable; l < newmax; ++l)
+ {
+ table[l] = 0;
+ check[l] = -1;
+ }
+
+ return(newmax);
+}
OpenPOWER on IntegriCloud