diff options
author | João Valverde <j@v6e.pt> | 2023-01-02 00:52:21 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2023-01-02 01:19:51 +0000 |
commit | f5bfe8978576d26e1ef0501d4f2a5aaa35af344a (patch) | |
tree | 226f233eaf09590f8c7d9920532717a4c3571d05 /epan | |
parent | 5d8f495233bab19d9b019b32ed9c9f326015b039 (diff) |
dfilter: Replace global variable
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dfilter/dfilter-int.h | 1 | ||||
-rw-r--r-- | epan/dfilter/dfilter.c | 13 | ||||
-rw-r--r-- | epan/dfilter/scanner.l | 16 |
3 files changed, 14 insertions, 16 deletions
diff --git a/epan/dfilter/dfilter-int.h b/epan/dfilter/dfilter-int.h index 0fd1f0bbdc..93af43d0e0 100644 --- a/epan/dfilter/dfilter-int.h +++ b/epan/dfilter/dfilter-int.h @@ -70,6 +70,7 @@ typedef struct { */ typedef struct { dfwork_t *dfw; + stnode_t *df_lval; GString* quoted_string; gboolean raw_string; df_loc_t string_loc; diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c index ea57e4735a..a862451e08 100644 --- a/epan/dfilter/dfilter.c +++ b/epan/dfilter/dfilter.c @@ -438,7 +438,6 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp, #endif while (1) { - df_lval = stnode_new_empty(STTYPE_UNINITIALIZED); token = df_yylex(scanner); /* Check for scanner failure */ @@ -456,12 +455,12 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp, ws_noisy("(%u) Token %d %s %s", ++token_count, token, tokenstr(token), - stnode_token(df_lval)); + stnode_token(state.df_lval)); /* Give the token to the parser */ - Dfilter(ParserObj, token, df_lval, dfw); + Dfilter(ParserObj, token, state.df_lval, dfw); /* The parser has freed the lval for us. */ - df_lval = NULL; + state.df_lval = NULL; if (dfw->parse_failure) { failure = TRUE; @@ -472,9 +471,9 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp, /* If we created a df_lval_t but didn't use it, free it; the * parser doesn't know about it and won't free it for us. */ - if (df_lval) { - stnode_free(df_lval); - df_lval = NULL; + if (state.df_lval) { + stnode_free(state.df_lval); + state.df_lval = NULL; } /* Tell the parser that we have reached the end of input; that diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l index 117bfec7fe..a273e99d81 100644 --- a/epan/dfilter/scanner.l +++ b/epan/dfilter/scanner.l @@ -75,8 +75,6 @@ */ DIAG_OFF_FLEX() -stnode_t *df_lval; - WS_WARN_UNUSED static int set_lval_simple(df_scanner_state_t *state, int token, const char *token_value, sttype_id_t type_id); #define simple(token) (update_location(yyextra, yytext), set_lval_simple(yyextra, token, yytext, STTYPE_UNINITIALIZED)) #define test(token) (update_location(yyextra, yytext), set_lval_simple(yyextra, token, yytext, STTYPE_TEST)) @@ -508,28 +506,28 @@ update_string_loc(df_scanner_state_t *state, const char *text) static int set_lval_simple(df_scanner_state_t *state, int token, const char *token_value, sttype_id_t type_id) { - stnode_init(df_lval, type_id, NULL, g_strdup(token_value), state->location); + state->df_lval = stnode_new(type_id, NULL, g_strdup(token_value), state->location); return token; } static int set_lval_literal(df_scanner_state_t *state, const char *token_value) { - stnode_init(df_lval, STTYPE_LITERAL, g_strdup(token_value), g_strdup(token_value), state->location); + state->df_lval = stnode_new(STTYPE_LITERAL, g_strdup(token_value), g_strdup(token_value), state->location); return TOKEN_LITERAL; } static int set_lval_identifier(df_scanner_state_t *state, const char *token_value) { - stnode_init(df_lval, STTYPE_LITERAL, g_strdup(token_value), g_strdup(token_value), state->location); + state->df_lval = stnode_new(STTYPE_LITERAL, g_strdup(token_value), g_strdup(token_value), state->location); return TOKEN_IDENTIFIER; } static int set_lval_constant(df_scanner_state_t *state, const char *token_value) { - stnode_init(df_lval, STTYPE_LITERAL, g_strdup(token_value), g_strdup(token_value), state->location); + state->df_lval = stnode_new(STTYPE_LITERAL, g_strdup(token_value), g_strdup(token_value), state->location); return TOKEN_CONSTANT; } @@ -549,7 +547,7 @@ set_lval_quoted_string(df_scanner_state_t *state, GString *quoted_string) char *token_value; token_value = ws_escape_string_len(NULL, quoted_string->str, quoted_string->len, true); - stnode_init(df_lval, STTYPE_STRING, quoted_string, token_value, state->string_loc); + state->df_lval = stnode_new(STTYPE_STRING, quoted_string, token_value, state->string_loc); return TOKEN_STRING; } @@ -565,14 +563,14 @@ set_lval_charconst(df_scanner_state_t *state, GString *quoted_string) g_free(token_value); return SCAN_FAILED; } - stnode_init(df_lval, STTYPE_CHARCONST, g_memdup2(&number, sizeof(number)), token_value, state->string_loc); + state->df_lval = stnode_new(STTYPE_CHARCONST, g_memdup2(&number, sizeof(number)), token_value, state->string_loc); return TOKEN_CHARCONST; } static int set_lval_field(df_scanner_state_t *state, const char *token_value, const header_field_info *hfinfo) { - stnode_init(df_lval, STTYPE_FIELD, (gpointer)hfinfo, g_strdup(token_value), state->location); + state->df_lval = stnode_new(STTYPE_FIELD, (gpointer)hfinfo, g_strdup(token_value), state->location); return TOKEN_FIELD; } |