lex.patch (5432B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: lex.patch 8 * Purpose: Add additional error checking to generated flex code 9 * Patch validated with Flex 2.5.31 and 2.5.35 10 * This is expected to apply with offsets from 2.5.31 to 2.5.34 11 * Known not to apply with 2.5.37 12 */ 13 14 15 --- cint_c.lex.c 2013-03-20 11:06:22.275687000 -0700 16 +++ cint_c.lex.c.new 2013-03-20 11:10:19.326809000 -0700 17 @@ -349,7 +349,6 @@ typedef int yy_state_type; 18 static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); 19 static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); 20 static int yy_get_next_buffer (yyscan_t yyscanner ); 21 -static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); 22 23 /* Done after the current pattern has been matched and before the 24 * corresponding action - sets up yytext. 25 @@ -898,11 +897,6 @@ static int input (yyscan_t yyscanner ); 26 #define YY_START_STACK_INCR 25 27 #endif 28 29 -/* Report a fatal error. */ 30 -#ifndef YY_FATAL_ERROR 31 -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) 32 -#endif 33 - 34 /* end tables serialization structures and prototypes */ 35 36 /* Default declaration of generated scanner - a define so the user can 37 @@ -931,6 +925,13 @@ extern int cint_c_lex (YYSTYPE * yylval_ 38 #define YY_RULE_SETUP \ 39 YY_USER_ACTION 40 41 +/* 42 + * BRCM: Check buffer stack 43 + */ 44 +#ifndef YY_CHECK_BUFFER_STACK 45 +#define YY_CHECK_BUFFER_STACK if (!yyg->yy_buffer_stack) YY_FATAL_ERROR("buffer error") 46 +#endif 47 + 48 /** The main scanner function which does all the work. 49 */ 50 YY_DECL 51 @@ -957,6 +958,7 @@ YY_DECL 52 #ifdef YY_USER_INIT 53 YY_USER_INIT; 54 #endif 55 + YY_CHECK_BUFFER_STACK; 56 57 if ( ! yyg->yy_start ) 58 yyg->yy_start = 1; /* first start state */ 59 @@ -1679,6 +1681,7 @@ ECHO; 60 /* Undo the effects of YY_DO_BEFORE_ACTION. */ 61 *yy_cp = yyg->yy_hold_char; 62 YY_RESTORE_YY_MORE_OFFSET 63 + YY_CHECK_BUFFER_STACK; 64 65 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) 66 { 67 @@ -2085,6 +2088,7 @@ static int yy_get_next_buffer (yyscan_t 68 69 if ( ! YY_CURRENT_BUFFER ){ 70 cint_c_ensure_buffer_stack (yyscanner); 71 + YY_CHECK_BUFFER_STACK; 72 YY_CURRENT_BUFFER_LVALUE = 73 cint_c__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); 74 } 75 @@ -2118,6 +2122,7 @@ static int yy_get_next_buffer (yyscan_t 76 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; 77 } 78 79 + YY_CHECK_BUFFER_STACK; 80 YY_CURRENT_BUFFER_LVALUE = new_buffer; 81 cint_c__load_buffer_state(yyscanner ); 82 83 @@ -2271,6 +2276,7 @@ void cint_c_push_buffer_state (YY_BUFFER 84 /* Only push if top exists. Otherwise, replace top. */ 85 if (YY_CURRENT_BUFFER) 86 yyg->yy_buffer_stack_top++; 87 + YY_CHECK_BUFFER_STACK; 88 YY_CURRENT_BUFFER_LVALUE = new_buffer; 89 90 /* copied from cint_c__switch_to_buffer. */ 91 @@ -2314,11 +2320,11 @@ static void cint_c_ensure_buffer_stack ( 92 * immediate realloc on the next call. 93 */ 94 num_to_alloc = 1; 95 - yyg->yy_buffer_stack = (struct yy_buffer_state**)cint_c_alloc 96 - (num_to_alloc * sizeof(struct yy_buffer_state*) 97 + yyg->yy_buffer_stack = (struct yy_buffer_state**)cint_c_realloc 98 + (NULL, num_to_alloc * sizeof(struct yy_buffer_state*) 99 , yyscanner); 100 101 - memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); 102 + cint_cparser_memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); 103 104 yyg->yy_buffer_stack_max = num_to_alloc; 105 yyg->yy_buffer_stack_top = 0; 106 @@ -2337,7 +2343,7 @@ static void cint_c_ensure_buffer_stack ( 107 , yyscanner); 108 109 /* zero only the new slots.*/ 110 - memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); 111 + cint_cparser_memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); 112 yyg->yy_buffer_stack_max = num_to_alloc; 113 } 114 } 115 @@ -2414,16 +2420,6 @@ YY_BUFFER_STATE cint_c__scan_bytes (yyc 116 return b; 117 } 118 119 -#ifndef YY_EXIT_FAILURE 120 -#define YY_EXIT_FAILURE 2 121 -#endif 122 - 123 -static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) 124 -{ 125 - (void) fprintf( stderr, "%s\n", msg ); 126 - exit( YY_EXIT_FAILURE ); 127 -} 128 - 129 /* Redefine yyless() so it works in section 3 code. */ 130 131 #undef yyless 132 @@ -2535,7 +2531,7 @@ void cint_c_set_lineno (int line_number 133 134 /* lineno is only valid if an input buffer exists. */ 135 if (! YY_CURRENT_BUFFER ) 136 - yy_fatal_error( "cint_c_set_lineno called with no buffer" , yyscanner); 137 + YY_FATAL_ERROR( "cint_c_set_lineno called with no buffer" ); 138 139 yylineno = line_number; 140 } 141 @@ -2550,7 +2546,7 @@ void cint_c_set_column (int column_no , 142 143 /* column is only valid if an input buffer exists. */ 144 if (! YY_CURRENT_BUFFER ) 145 - yy_fatal_error( "cint_c_set_column called with no buffer" , yyscanner); 146 + YY_FATAL_ERROR( "cint_c_set_column called with no buffer" ); 147 148 yycolumn = column_no; 149 } 150 @@ -2664,7 +2660,7 @@ int cint_c_lex_init(yyscan_t* ptr_yy_glo 151 return 1; 152 } 153 154 - memset(*ptr_yy_globals,0,sizeof(struct yyguts_t)); 155 + cint_cparser_memset(*ptr_yy_globals,0,sizeof(struct yyguts_t)); 156 157 return yy_init_globals ( *ptr_yy_globals ); 158 }