forked from osmocom/wireshark
If we're reading from a string, don't fclose yyin.
yyin is initialized to stdin. When we're reading from files, we set it so that it points to the FILE from which we're reading, but when we're reading from a string, we don't set it, leaving it to point to stdin. This means that, just as the "read from the input" routine has to be set differently when reading from a file or a string, the "close the current input" routine has to be set differently as well. Bug: 14577 Change-Id: Ie05880775612867e9037ace2de0cd0a0dd2fabb5 Reviewed-on: https://code.wireshark.org/review/26719 Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
82bfb259d3
commit
9d87f607ee
|
@ -162,6 +162,7 @@ typedef struct {
|
|||
unsigned* attr_uint;
|
||||
|
||||
size_t (*current_yyinput)(char*,size_t,yyscan_t);
|
||||
int (*current_close)(FILE *fh);
|
||||
|
||||
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
|
||||
int include_stack_ptr;
|
||||
|
@ -379,7 +380,7 @@ description_attr description=\042
|
|||
<<EOF>> {
|
||||
if (!yyin) yyterminate();
|
||||
|
||||
fclose(yyin);
|
||||
yyextra->current_close(yyin);
|
||||
D(("closing: %p %i\n",(void*)yyin,yyextra->include_stack_ptr));
|
||||
|
||||
if ( --yyextra->include_stack_ptr < 0 ) {
|
||||
|
@ -708,6 +709,16 @@ string_input(char* buf, size_t max, yyscan_t scanner)
|
|||
return max;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're reading from a string, yyin is set to stdin, and we don't
|
||||
* want to close that.
|
||||
*/
|
||||
static int
|
||||
string_close(FILE *fh _U_)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FILE *
|
||||
ddict_open(const char* system_directory, const char* filename)
|
||||
{
|
||||
|
@ -786,6 +797,7 @@ ddict_scan(const char* system_directory, const char* filename, int dbg)
|
|||
* of the file contents in memory.
|
||||
*/
|
||||
state.current_yyinput = file_input;
|
||||
state.current_close = fclose;
|
||||
state.include_stack_ptr = 0;
|
||||
|
||||
in = ddict_open(system_directory,filename);
|
||||
|
@ -827,6 +839,7 @@ ddict_scan(const char* system_directory, const char* filename, int dbg)
|
|||
* rest of the work.
|
||||
*/
|
||||
state.current_yyinput = string_input;
|
||||
state.current_close = string_close;
|
||||
|
||||
if (DiamDict_lex_init(&scanner) != 0) {
|
||||
/* Note: cannot be reached since memory allocation failure terminates early */
|
||||
|
|
Loading…
Reference in New Issue