*** flex-2.5.4/scan.l Sat Jul 26 19:44:13 1997 --- flex-2.5.4/scan.l.s-max Fri Nov 27 21:28:19 1998 *************** *** 31,36 **** --- 31,37 ---- #include "flexdef.h" #include "parse.h" + #include /* For INT_MAX. */ #define ACTION_ECHO add_action( yytext ) #define ACTION_IFDEF(def, should_define) \ *************** *** 98,105 **** int doing_codeblock = false; int i; ! Char nmdef[MAXLINE], myesc(); ! { ^{WS} indented_code = true; BEGIN(CODEBLOCK); --- 99,113 ---- int doing_codeblock = false; int i; ! Char myesc(); ! int nmdeflen = MAXLINE; ! Char *nmdef = allocate_Character_array(nmdeflen); ! ! if (nmdef == NULL) /* Failed initial allocation. */ ! { ! fprintf(stderr, "Cannot allocate nmdef buffer.\n"); ! exit(1); ! } { ^{WS} indented_code = true; BEGIN(CODEBLOCK); *************** *** 184,193 **** {WS} /* separates name and definition */ {NOT_WS}.* { strcpy( (char *) nmdef, yytext ); /* Skip trailing whitespace. */ ! for ( i = strlen( (char *) nmdef ) - 1; i >= 0 && (nmdef[i] == ' ' || nmdef[i] == '\t'); --i ) ; --- 192,227 ---- {WS} /* separates name and definition */ {NOT_WS}.* { + const int len = strlen(yytext); + + /* Grow nmdef if not big enough to hold yytext. */ + while (len >= nmdeflen) + { + /* Paranoid check for nmdeflen == INT_MAX. */ + if (nmdeflen == INT_MAX) { + fprintf(stderr, "Name definition too long.\n"); + exit(1); + } + + /* Similar paranoia: double only up to INT_MAX. */ + nmdeflen = ((INT_MAX / 2) < nmdeflen) + ? INT_MAX + : nmdeflen * 2; + + /* Now we can try to expand nmdef. */ + nmdef = reallocate_Character_array(nmdef, nmdeflen); + if (nmdef == NULL) + { + fprintf(stderr, + "Out of memory growing nmdef buffer.\n"); + exit(1); + } + } + strcpy( (char *) nmdef, yytext ); /* Skip trailing whitespace. */ ! for ( i = len - 1; i >= 0 && (nmdef[i] == ' ' || nmdef[i] == '\t'); --i ) ;