Use -1 rather than 0 as the SCAN_FAILED return value from the lexical
analyzer on errors, and check for SCAN_FAILED from the lexical analyzer and abort the parse if we see it; 0 means "end of input", and we want to distinguish errors from end-of-input, so that we can report errors as such. If we see end-of-input while parsing a double-quoted string, report the error (missing closing quote). Fix the URL for the "Start conditions" section of the Flex manual. svn path=/trunk/; revision=10044
This commit is contained in:
parent
b9b4a23834
commit
60096bfad9
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: dfilter-int.h,v 1.7 2002/08/28 20:40:55 jmayer Exp $
|
||||
* $Id: dfilter-int.h,v 1.8 2004/02/11 22:52:54 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -34,8 +34,8 @@ struct _dfilter_t {
|
|||
int num_registers;
|
||||
GList **registers;
|
||||
gboolean *attempted_load;
|
||||
int *interesting_fields;
|
||||
int num_interesting_fields;
|
||||
int *interesting_fields;
|
||||
int num_interesting_fields;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
@ -57,9 +57,11 @@ void Dfilter(void*, int, stnode_t*, dfwork_t*);
|
|||
/* Scanner's lval */
|
||||
extern stnode_t *df_lval;
|
||||
|
||||
/* Return value for error in scanner. */
|
||||
#define SCAN_FAILED -1 /* not 0, as that means end-of-input */
|
||||
|
||||
/* Set dfilter_error_msg_buf and dfilter_error_msg */
|
||||
void
|
||||
dfilter_fail(char *format, ...);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: dfilter.c,v 1.14 2002/12/02 23:28:16 guy Exp $
|
||||
* $Id: dfilter.c,v 1.15 2004/02/11 22:52:54 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -204,6 +204,17 @@ dfilter_compile(const gchar *text, dfilter_t **dfp)
|
|||
df_lval = stnode_new(STTYPE_UNINITIALIZED, NULL);
|
||||
token = df_lex();
|
||||
|
||||
/* Check for scanner failure */
|
||||
if (token == SCAN_FAILED) {
|
||||
/* Free the stnode_t that we just generated, since
|
||||
* we're going to give up on parsing. */
|
||||
stnode_free(df_lval);
|
||||
df_lval = NULL;
|
||||
|
||||
/* Give up. */
|
||||
goto FAILURE;
|
||||
}
|
||||
|
||||
/* Check for end-of-input */
|
||||
if (token == 0) {
|
||||
/* Tell the parser that we have reached the end of input */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
%{
|
||||
/*
|
||||
* $Id: scanner.l,v 1.14 2004/01/07 05:24:04 gram Exp $
|
||||
* $Id: scanner.l,v 1.15 2004/02/11 22:52:54 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -48,8 +48,6 @@ static int simple(int token);
|
|||
static gboolean str_to_guint32(char *s, guint32* pint);
|
||||
GString* quoted_string = NULL;
|
||||
|
||||
#define SCAN_FAILED 0
|
||||
|
||||
%}
|
||||
|
||||
%x RANGE_INT
|
||||
|
@ -128,7 +126,7 @@ GString* quoted_string = NULL;
|
|||
/* The example of how to scan for strings was taken from
|
||||
the flex 2.5.4 manual, from the section "Start Conditions".
|
||||
See:
|
||||
http://www.gnu.org/manual/flex-2.5.4/html_node/flex_11.html */
|
||||
http://www.gnu.org/software/flex/manual/html_node/flex_11.html */
|
||||
|
||||
BEGIN(DQUOTE);
|
||||
/* A previous filter that failed to compile due to
|
||||
|
@ -144,6 +142,17 @@ GString* quoted_string = NULL;
|
|||
quoted_string = g_string_new("");
|
||||
}
|
||||
|
||||
<DQUOTE><<EOF>> {
|
||||
/* unterminated string */
|
||||
/* The example of how to handle unclosed strings was taken from
|
||||
the flex 2.5.4 manual, from the section "End-of-file rules".
|
||||
See:
|
||||
http://www.gnu.org/software/flex/manual/html_node/flex_13.html */
|
||||
|
||||
dfilter_fail("The final quote was missing from a quoted string.");
|
||||
return SCAN_FAILED;
|
||||
}
|
||||
|
||||
<DQUOTE>\" {
|
||||
/* end quote */
|
||||
char *my_string = g_strdup(quoted_string->str);
|
||||
|
|
Loading…
Reference in New Issue