Permalink
Browse files

Older versions of Flex (e.g., 2.5.2, which at least one user had) dump

core if the YY_FLUSH_BUFFER macro is called when there's no current
buffer (e.g., before any scanning has been done).

So, instead, when using Flex, we use "yy_scan_string()" to specify that
the scanner should read from the filter expression string, rather than
defining our own YY_INPUT macro, and we add a "lex_cleanup()" routine,
called after parsing is complete, to delete the buffer allocated by
"yy_scan_string()", which arranges that, when we next hand the scanner a
string, it doesn't then return to the parser cruft left over from the
previous parse.
  • Loading branch information...
yuguy committed Jul 13, 2000
1 parent e7039d2 commit 0d0297bdd143e82898a9a4e2a4896d779a56f63b
Showing with 23 additions and 26 deletions.
  1. +2 −1 gencode.c
  2. +2 −1 gencode.h
  3. +19 −24 scanner.l
View
@@ -21,7 +21,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.113 2000-07-11 00:37:04 assar Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.114 2000-07-13 06:51:56 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -276,6 +276,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
root = NULL;
bpf_pcap = p;
if (setjmp(top_ctx)) {
+ lex_cleanup();
freechunks();
return (-1);
}
View
@@ -18,7 +18,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.40 2000-07-11 00:37:07 assar Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.41 2000-07-13 06:51:56 guy Exp $ (LBL)
*/
/* Address qualifiers. */
@@ -186,6 +186,7 @@ char *sdup(const char *);
struct bpf_insn *icode_to_fcode(struct block *, int *);
int pcap_parse(void);
void lex_init(char *);
+void lex_cleanup(void);
void sappend(struct slist *, struct slist *);
/* XXX */
View
@@ -22,7 +22,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.64 2000-07-11 00:37:08 assar Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.65 2000-07-13 06:51:57 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -59,31 +59,17 @@ static inline int xdtoi(int);
#ifdef FLEX_SCANNER
#define YY_NO_UNPUT
-#undef YY_INPUT
-#define YY_INPUT(buf, result, max)\
- {\
- char *src = in_buffer;\
- int i;\
-\
- if (*src == 0)\
- result = YY_NULL;\
- else {\
- for (i = 0; *src && i < max; ++i)\
- buf[i] = *src++;\
- in_buffer += i;\
- result = i;\
- }\
- }
+static YY_BUFFER_STATE in_buffer;
#else
+static char *in_buffer;
+
#undef getc
#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
#endif
#define yylval pcap_lval
extern YYSTYPE yylval;
-static char *in_buffer;
-
%}
N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
@@ -272,13 +258,23 @@ void
lex_init(buf)
char *buf;
{
+#ifdef FLEX_SCANNER
+ in_buffer = yy_scan_string(buf);
+#else
in_buffer = buf;
+#endif
+}
+
+/*
+ * Do any cleanup necessary after parsing.
+ */
+void
+lex_cleanup()
+{
#ifdef FLEX_SCANNER
- /*
- * Flush the scanner's input buffer, so that there's no cruft
- * left over from a previous parse.
- */
- YY_FLUSH_BUFFER;
+ if (in_buffer != NULL)
+ yy_delete_buffer(in_buffer);
+ in_buffer = NULL;
#endif
}
@@ -331,4 +327,3 @@ stoi(s)
return n;
}
-

0 comments on commit 0d0297b

Please sign in to comment.