Allocates the stack if it does not exist. * Guarantees space for at least one push. */
| 2157 | * Guarantees space for at least one push. |
| 2158 | */ |
| 2159 | static void ap_expr_yyensure_buffer_stack (yyscan_t yyscanner) |
| 2160 | { |
| 2161 | int num_to_alloc; |
| 2162 | struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; |
| 2163 | |
| 2164 | if (!yyg->yy_buffer_stack) { |
| 2165 | |
| 2166 | /* First allocation is just for 2 elements, since we don't know if this |
| 2167 | * scanner will even need a stack. We use 2 instead of 1 to avoid an |
| 2168 | * immediate realloc on the next call. |
| 2169 | */ |
| 2170 | num_to_alloc = 1; |
| 2171 | yyg->yy_buffer_stack = (struct yy_buffer_state**)ap_expr_yyalloc |
| 2172 | (num_to_alloc * sizeof(struct yy_buffer_state*) |
| 2173 | , yyscanner); |
| 2174 | if ( ! yyg->yy_buffer_stack ) |
| 2175 | YY_FATAL_ERROR( "out of dynamic memory in ap_expr_yyensure_buffer_stack()" ); |
| 2176 | |
| 2177 | memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); |
| 2178 | |
| 2179 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 2180 | yyg->yy_buffer_stack_top = 0; |
| 2181 | return; |
| 2182 | } |
| 2183 | |
| 2184 | if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ |
| 2185 | |
| 2186 | /* Increase the buffer to prepare for a possible push. */ |
| 2187 | int grow_size = 8 /* arbitrary grow size */; |
| 2188 | |
| 2189 | num_to_alloc = yyg->yy_buffer_stack_max + grow_size; |
| 2190 | yyg->yy_buffer_stack = (struct yy_buffer_state**)ap_expr_yyrealloc |
| 2191 | (yyg->yy_buffer_stack, |
| 2192 | num_to_alloc * sizeof(struct yy_buffer_state*) |
| 2193 | , yyscanner); |
| 2194 | if ( ! yyg->yy_buffer_stack ) |
| 2195 | YY_FATAL_ERROR( "out of dynamic memory in ap_expr_yyensure_buffer_stack()" ); |
| 2196 | |
| 2197 | /* zero only the new slots.*/ |
| 2198 | memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); |
| 2199 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | /** Setup the input buffer state to scan directly from a user-specified character buffer. |
| 2204 | * @param base the character buffer |
no test coverage detected