X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=token.c;h=807f08fc34b4f2789b90bc557e5758dc11711018;hb=37694c99b02f939fc259c1e180359afb887acd55;hp=55dbc290980722d06ed144755e43bb85587965a5;hpb=c38505ee4b2a0de59926107e52fb8bb84041a0e4;p=rmac diff --git a/token.c b/token.c index 55dbc29..807f08f 100644 --- a/token.c +++ b/token.c @@ -1,7 +1,7 @@ // -// RMAC - Reboot's Macro Assembler for all Atari computers +// RMAC - Renamed Macro Assembler for all Atari computers // TOKEN.C - Token Handling -// Copyright (C) 199x Landon Dyer, 2011-2020 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -22,7 +22,7 @@ int lnsave; // 1; strcpy() text of current line -uint16_t curlineno; // Current line number (64K max currently) +uint32_t curlineno; // Current line number (64K max currently) int totlines; // Total # of lines int mjump_align = 0; // mjump alignment flag char lntag; // Line tag @@ -40,13 +40,6 @@ TOKEN tokeol[1] = {EOL}; // Bailout end-of-line token char * string[TOKBUFSIZE*2];// Token buffer string pointer storage int optimizeOff; // Optimization override flag -// File record, used to maintain a list of every include file ever visited -#define FILEREC struct _filerec -FILEREC -{ - FILEREC * frec_next; - char * frec_name; -}; FILEREC * filerec; FILEREC * last_fr; @@ -673,7 +666,6 @@ overflow: char * GetNextMacroLine(void) { IMACRO * imacro = cur_inobj->inobj.imacro; -// LONG * strp = imacro->im_nextln; LLIST * strp = imacro->im_nextln; if (strp == NULL) // End-of-macro @@ -792,7 +784,7 @@ int fpop(void) if (numUnmatched > 0) warn("missing %d .endif(s)", numUnmatched); - tok = inobj->in_otok; // Restore tok and otok + tok = inobj->in_otok; // Restore tok and etok etok = inobj->in_etok; switch (inobj->in_type) @@ -1044,7 +1036,13 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } // macro-type blocks, since it is expensive to unconditionally copy every // line. if (lnsave) + { + // Sanity check + if (strlen(ln) > LNSIZ) + return error("line too long (%d, max %d)", strlen(ln), LNSIZ); + strcpy(lnbuf, ln); + } // General housekeeping tok = tokeol; // Set "tok" to EOL in case of error @@ -1075,6 +1073,12 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } // o handle multiple-character tokens (constants, strings, etc.). for(; *ln!=EOS;) { + // Check to see if there's enough space in the token buffer + if (tk.cp >= ((uint8_t *)(&tokbuf[TOKBUFSIZE])) - 20) + { + return error("token buffer overrun"); + } + // Skip whitespace, handle EOL while (chrtab[*ln] & WHITE) ln++; @@ -1651,7 +1655,7 @@ int d_goto(WORD unused) { // Compare names (sleazo string compare) char * s1 = sym; - char * s2 = defln->line; + char * s2 = defln->line + 1; // Either we will match the strings to EOS on both, or we will // match EOS on string 1 to whitespace on string 2. Otherwise, we