savestr now saves strings in both a file and in core; fixed
authorRobert R. Henry <rrh@ucbvax.Berkeley.EDU>
Sat, 2 Jul 1983 00:43:17 +0000 (16:43 -0800)
committerRobert R. Henry <rrh@ucbvax.Berkeley.EDU>
Sat, 2 Jul 1983 00:43:17 +0000 (16:43 -0800)
a bug with savestr being too generous in saving strings in core

SCCS-vsn: old/as.vax/asparse.c 4.17
SCCS-vsn: old/as.vax/assyms.c 4.13
SCCS-vsn: old/as.vax/asscan2.c 4.12

usr/src/old/as.vax/asparse.c
usr/src/old/as.vax/asscan2.c
usr/src/old/as.vax/assyms.c

index a9d57ef..a30f390 100644 (file)
@@ -2,7 +2,7 @@
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
-static char sccsid[] = "@(#)asparse.c 4.16 %G%";
+static char sccsid[] = "@(#)asparse.c 4.17 %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -666,12 +666,7 @@ restlab:
                stringp->sd_strlen += 1;
                shiftover(CM);
        } else {
                stringp->sd_strlen += 1;
                shiftover(CM);
        } else {
-               static char nullstr[1];
-               static  struct  strdesc strdp;
-               strdp.sd_stroff = strfilepos;
-               strdp.sd_strlen = 0;
-               strdp.sd_place = STR_BOTH;
-               stpt->s_name = (char *)savestr(nullstr, &strdp);
+               stpt->s_name = (char *)savestr("\0", 0, STR_BOTH);
        }
        goto tailstab;
        break;
        }
        goto tailstab;
        break;
index a6a3386..3f33a82 100644 (file)
@@ -2,7 +2,7 @@
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
-static char sccsid[] = "@(#)asscan2.c 4.11 %G%";
+static char sccsid[] = "@(#)asscan2.c 4.12 %G%";
 #endif not lint
 
 #include "asscanl.h"
 #endif not lint
 
 #include "asscanl.h"
@@ -47,12 +47,6 @@ fillinbuffer()
        Ginbufptr = inbuffer + 1;
 }
 
        Ginbufptr = inbuffer + 1;
 }
 
-#if NCPName < NCPString
-char   strtext[NCPString + 1];
-#else
-#      define  strtext yytext
-#endif
-
 scan_dot_s(bufferbox)
        struct tokbufdesc *bufferbox;
 {
 scan_dot_s(bufferbox)
        struct tokbufdesc *bufferbox;
 {
@@ -69,11 +63,10 @@ scan_dot_s(bufferbox)
                ptrall  lgbackpatch;    /* where to stuff a string length */
        reg     ptrall  bufptr;         /* where to stuff tokens */
                ptrall  bufub;          /* where not to stuff tokens */
                ptrall  lgbackpatch;    /* where to stuff a string length */
        reg     ptrall  bufptr;         /* where to stuff tokens */
                ptrall  bufub;          /* where not to stuff tokens */
-       reg     int     strlg;          /* the length of a string */
                long    intval;         /* value of int */
                int     linescrossed;   /* when doing strings and comments */
                struct  Opcode          opstruct;
                long    intval;         /* value of int */
                int     linescrossed;   /* when doing strings and comments */
                struct  Opcode          opstruct;
-               struct  strdesc strd;   /* for building DQ strings */
+       reg     int     strlg;          /* the length of a string */
 
        (bytetoktype *)bufptr = (bytetoktype *) & (bufferbox->toks[0]); 
        (bytetoktype *)bufub = &(bufferbox->toks[AVAILTOKS]);
 
        (bytetoktype *)bufptr = (bytetoktype *) & (bufferbox->toks[0]); 
        (bytetoktype *)bufub = &(bufferbox->toks[AVAILTOKS]);
@@ -81,13 +74,7 @@ scan_dot_s(bufferbox)
        MEMTOREGBUF;
        if (newfflag){
                newfflag = 0;
        MEMTOREGBUF;
        if (newfflag){
                newfflag = 0;
-               strd.sd_stroff = strfilepos;
-               strd.sd_place = STR_BOTH;
-               strd.sd_strlen = strlen(newfname) + 1;
-               fputs(newfname, strfile);
-               putc(0, strfile);
-               strfilepos += strd.sd_strlen;
-               ryylval = (int)savestr(newfname, &strd);
+               ryylval = (int)savestr(newfname, strlen(newfname)+1, STR_BOTH);
 
                ptoken(bufptr, IFILE);
                ptoken(bufptr, STRING);
 
                ptoken(bufptr, IFILE);
                ptoken(bufptr, STRING);
@@ -319,9 +306,7 @@ scan_dot_s(bufferbox)
        case DQ:
           eatstr:
                linescrossed = 0;
        case DQ:
           eatstr:
                linescrossed = 0;
-               strd.sd_stroff = strfilepos;
-               strd.sd_place = STR_FILE;
-               for (strd.sd_strlen = 0; /*VOID*/; strd.sd_strlen++){
+               for (strlg = 0; /*VOID*/; strlg++){
                    switch(ch = getchar()){
                    case '"':
                        goto tailDQ;
                    switch(ch = getchar()){
                    case '"':
                        goto tailDQ;
@@ -381,18 +366,14 @@ scan_dot_s(bufferbox)
                        pint(bufptr, linescrossed);
                }
                /*
                        pint(bufptr, linescrossed);
                }
                /*
-                *      put the string in strtext into the string pool
-                *
                 *      Cheat: append a trailing null to the string
                 *      and then adjust the string length to ignore
                 *      the trailing null.  If any STRING client requires
                 *      the trailing null, the client can just change STRLEN
                 */
                 *      Cheat: append a trailing null to the string
                 *      and then adjust the string length to ignore
                 *      the trailing null.  If any STRING client requires
                 *      the trailing null, the client can just change STRLEN
                 */
-               val = STRING;
                putc(0, strfile);
                putc(0, strfile);
-               strd.sd_strlen += 1;
-               strfilepos += strd.sd_strlen;
-               ryylval = (int)savestr(strtext, &strd);
+               ryylval = (int)savestr((char *)0, strlg + 1, STR_FILE);
+               val = STRING;
                ((struct strdesc *)ryylval)->sd_strlen -= 1;
                goto ret;
 
                ((struct strdesc *)ryylval)->sd_strlen -= 1;
                goto ret;
 
index b4db319..4ae51df 100644 (file)
@@ -2,7 +2,7 @@
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
-static char sccsid[] = "@(#)assyms.c 4.12 %G%";
+static char sccsid[] = "@(#)assyms.c 4.13 %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -393,7 +393,6 @@ struct symtab **lookup(instflg)
        static  struct  symtab  **emptyslot;
        static  struct  hashdallop *emptyhd;
        static  struct  symtab  **hp_ub;
        static  struct  symtab  **emptyslot;
        static  struct  hashdallop *emptyhd;
        static  struct  symtab  **hp_ub;
-       static  struct  strdesc strdp;
 
        emptyslot = 0;
        for (nprobes = 0, from = yytext;
 
        emptyslot = 0;
        for (nprobes = 0, from = yytext;
@@ -443,44 +442,57 @@ struct symtab **lookup(instflg)
                hdallop->h_nused++;
                for (from = yytext, len = 0; *from++; len++)
                        continue;
                hdallop->h_nused++;
                for (from = yytext, len = 0; *from++; len++)
                        continue;
-               /*
-                *      save string and trailing null, both
-                *      internally, and in the string temporary file
-                */
-               strdp.sd_stroff = strfilepos;
-               strdp.sd_place = STR_BOTH;
-               strdp.sd_strlen = len + 1;      /* length and null */
-               fputs(yytext, strfile);         /* string */
-               putc(0, strfile);               /* null */
-               strfilepos += strdp.sd_strlen;
-               (*hp)->s_name = (char *)savestr(yytext, &strdp);
+               (*hp)->s_name = (char *)savestr(yytext, len + 1, STR_BOTH);
        }
        return(hp);
 }      /*end of lookup*/
 /*
        }
        return(hp);
 }      /*end of lookup*/
 /*
- *     save a string str, descriptor strdp, in the string pool
+ *     save a string str with len in the places indicated by place
  */
  */
-struct strdesc *savestr(str, strdp)
+struct strdesc *savestr(str, len, place)
        char    *str;
        char    *str;
-       struct  strdesc *strdp;
+       int     len;
+       int     place;
 {
        reg     struct  strdesc *res;
                int     tlen;
 {
        reg     struct  strdesc *res;
                int     tlen;
-
+       /*
+        *      Compute the total length of the record to live in core
+        */
        tlen = sizeof(struct strdesc) - sizeof(res->sd_string);
        tlen = sizeof(struct strdesc) - sizeof(res->sd_string);
-       if (strdp->sd_place & STR_FILE)
-               tlen += strdp->sd_strlen;
-
+       if (place & STR_CORE)
+               tlen += len;
+       /*
+        *      See if there is enough space for the record,
+        *      and allocate the record.
+        */
        if (tlen >= (STRPOOLDALLOP - strplhead->str_nalloc))
                strpoolalloc();
        res = (struct strdesc *)(strplhead->str_names + strplhead->str_nalloc);
        if (tlen >= (STRPOOLDALLOP - strplhead->str_nalloc))
                strpoolalloc();
        res = (struct strdesc *)(strplhead->str_names + strplhead->str_nalloc);
-       res[0] = *strdp;
-       if (strdp->sd_place & STR_FILE)
-               movestr(res[0].sd_string, str, strdp->sd_strlen);
+       /*
+        *      Save the string information that is always present
+        */
+       res->sd_stroff = strfilepos;
+       res->sd_strlen = len;
+       res->sd_place = place;
+       /*
+        *      Now, save the string itself.  If str is null, then
+        *      the characters have already been dumped to the file
+        */
+       if ((place & STR_CORE) && str)
+               movestr(res[0].sd_string, str, len);
+       if (place & STR_FILE){
+               if (str){
+                       fwrite(str, 1, len, strfile);
+               }
+               strfilepos += len;
+       }
+       /*
+        *      Adjust the in core string pool size
+        */
        strplhead->str_nalloc += tlen;
        return(res);
 }
        strplhead->str_nalloc += tlen;
        return(res);
 }
-
 /*
  *     The relocation information is saved internally in an array of
  *     lists of relocation buffers.  The relocation buffers are
 /*
  *     The relocation information is saved internally in an array of
  *     lists of relocation buffers.  The relocation buffers are