Make sure we don't overflow various internal compiler buffers.

We may replace some of these tables with dynamically growing data
structures, but in the meantime we will not trash memory.
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index 0587dd9..733f188 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -1083,7 +1083,7 @@
     int dch;    // Macro state: Saves old value of ch during a macro playback.
     char* last_id;
     void* pSymbolBase;
-    void* pGlobalBase;
+    char* pGlobalBase;
     char* pVarsBase; // Value of variables
 
     InputStream* file;
@@ -1154,6 +1154,9 @@
     static const char operatorLevel[];
 
     void pdef(int t) {
+        if (dstk - sym_stk >= ALLOC_SIZE) {
+            error("Symbol table exhausted");
+        }
         *dstk++ = t;
     }
 
@@ -1219,6 +1222,9 @@
                 tokc = strtol(last_id, 0, 0);
                 tok = TOK_NUM;
             } else {
+                if (dstk - sym_stk + 1 > ALLOC_SIZE) {
+                    error("symbol stack overflow");
+                }
                 * dstk = TAG_TOK; /* no need to mark end of string (we
                  suppose data is initialized to zero by calloc) */
                 tok = (intptr_t) (strstr(sym_stk, (last_id - 1))
@@ -1226,6 +1232,9 @@
                 * dstk = 0; /* mark real end of ident for dlsym() */
                 tok = tok * 8 + TOK_IDENT;
                 if (tok > TOK_DEFINE) {
+                    if (tok + 8 > ALLOC_SIZE) {
+                        error("Variable Table overflow.");
+                    }
                     tok = (intptr_t) (pVarsBase + tok);
                     /*        printf("tok=%s %x\n", last_id, tok); */
                     /* define handling */
@@ -1350,11 +1359,12 @@
             pGen->li((int) glo);
             while (ch != '\"') {
                 getq();
-                *glo++ = ch;
+                *allocGlobalSpace(1) = ch;
                 inp();
             }
             *glo = 0;
-            glo = (char*) (((intptr_t) glo + 4) & -4); /* align heap */
+            /* align heap */
+            allocGlobalSpace((char*) (((intptr_t) glo + 4) & -4) - glo);
             inp();
             next();
         } else {
@@ -1584,8 +1594,7 @@
                         loc = loc + 4;
                         *(int *) tok = -loc;
                     } else {
-                        *(int* *) tok = (int*) glo;
-                        glo = glo + 4;
+                        *(int* *) tok = (int*) allocGlobalSpace(4);
                     }
                     next();
                     if (tok == ',')
@@ -1621,13 +1630,22 @@
         }
     }
 
+    char* allocGlobalSpace(int bytes) {
+        if (glo - pGlobalBase + bytes > ALLOC_SIZE) {
+            error("Global space exhausted");
+        }
+        char* result = glo;
+        glo += bytes;
+        return result;
+    }
+
     void cleanup() {
         if (sym_stk != 0) {
             free(sym_stk);
             sym_stk = 0;
         }
         if (pGlobalBase != 0) {
-            free((void*) pGlobalBase);
+            free(pGlobalBase);
             pGlobalBase = 0;
         }
         if (pVarsBase != 0) {
@@ -1730,8 +1748,8 @@
             dstk = strcpy(sym_stk,
                     " int if else while break return for define main ")
                     + TOK_STR_SIZE;
-            pGlobalBase = calloc(1, ALLOC_SIZE);
-            glo = (char*) pGlobalBase;
+            pGlobalBase = (char*) calloc(1, ALLOC_SIZE);
+            glo = pGlobalBase;
             pVarsBase = (char*) calloc(1, ALLOC_SIZE);
             inp();
             next();