From: guy Date: Thu, 13 Jul 2000 06:51:56 +0000 (+0000) Subject: Older versions of Flex (e.g., 2.5.2, which at least one user had) dump X-Git-Tag: libpcap-0.6.1~119 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/0d0297bdd143e82898a9a4e2a4896d779a56f63b 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. --- diff --git a/gencode.c b/gencode.c index 6eab6ced..cf78df8c 100644 --- a/gencode.c +++ b/gencode.c @@ -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); } diff --git a/gencode.h b/gencode.h index c458911a..51c0e66d 100644 --- a/gencode.h +++ b/gencode.h @@ -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 */ diff --git a/scanner.l b/scanner.l index c6d789b5..1090b65d 100644 --- a/scanner.l +++ b/scanner.l @@ -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,22 +59,10 @@ 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 @@ -82,8 +70,6 @@ static inline int xdtoi(int); #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; } -