From 87a3522b47394d611e4eb7bb1ba360cff6a939dc Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 11 Jun 2017 14:18:52 +0100 Subject: Fix up some parser snafu for release mode --- Makefile | 2 +- src/filter-parser.y | 49 +++++++++++++++++++++++++++++++++++++++---------- test/basictests.c | 4 +++- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 26cf49f..5c9c7b8 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ else # __inline__ is a GCCism CFLAGS := $(CFLAGS) -Dinline="__inline__" endif -CFLAGS := $(CFLAGS) -D_POSIX_C_SOURCE=200809L +CFLAGS := $(CFLAGS) -D_POSIX_C_SOURCE=200809L -g REQUIRED_LIBS := nslog diff --git a/src/filter-parser.y b/src/filter-parser.y index bb225b6..2ccb3c8 100644 --- a/src/filter-parser.y +++ b/src/filter-parser.y @@ -33,6 +33,10 @@ static void filter_error(FILTER_LTYPE *loc, nslog_filter_t **output, const char nslog_filter_t *filter; } +%destructor { + nslog_filter_unref($$); +} + %token T_PATTERN %token T_LEVEL @@ -88,35 +92,45 @@ expression ::= term | '!' term level_filter: T_LEVEL_SPECIFIER T_LEVEL { - assert(nslog_filter_level_new($2, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_level_new($2, &$$) != NSLOG_NO_ERROR) { + YYABORT ; + } } ; category_filter: T_CATEGORY_SPECIFIER T_PATTERN { - assert(nslog_filter_category_new($2, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_category_new($2, &$$) != NSLOG_NO_ERROR) { + YYABORT ; + } } ; filename_filter: T_FILENAME_SPECIFIER T_PATTERN { - assert(nslog_filter_filename_new($2, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_filename_new($2, &$$) != NSLOG_NO_ERROR) { + YYABORT ; + } } ; dirname_filter: T_DIRNAME_SPECIFIER T_PATTERN { - assert(nslog_filter_dirname_new($2, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_dirname_new($2, &$$) != NSLOG_NO_ERROR) { + YYABORT ; + } } ; funcname_filter: T_FUNCNAME_SPECIFIER T_PATTERN { - assert(nslog_filter_funcname_new($2, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_funcname_new($2, &$$) != NSLOG_NO_ERROR) { + YYABORT ; + } } ; @@ -135,7 +149,11 @@ basic_filter: and_filter: '(' filter T_OP_AND filter ')' { - assert(nslog_filter_and_new($2, $4, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_and_new($2, $4, &$$) != NSLOG_NO_ERROR) { + nslog_filter_unref($2); + nslog_filter_unref($4); + YYABORT ; + } nslog_filter_unref($2); nslog_filter_unref($4); } @@ -144,7 +162,11 @@ and_filter: or_filter: '(' filter T_OP_OR filter ')' { - assert(nslog_filter_or_new($2, $4, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_or_new($2, $4, &$$) != NSLOG_NO_ERROR) { + nslog_filter_unref($2); + nslog_filter_unref($4); + YYABORT ; + } nslog_filter_unref($2); nslog_filter_unref($4); } @@ -153,7 +175,11 @@ or_filter: xor_filter: '(' filter '^' filter ')' { - assert(nslog_filter_xor_new($2, $4, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_xor_new($2, $4, &$$) != NSLOG_NO_ERROR) { + nslog_filter_unref($2); + nslog_filter_unref($4); + YYABORT ; + } nslog_filter_unref($2); nslog_filter_unref($4); } @@ -170,7 +196,10 @@ binary_filter: not_filter: '!' filter { - assert(nslog_filter_not_new($2, &$$) == NSLOG_NO_ERROR); + if (nslog_filter_not_new($2, &$$) != NSLOG_NO_ERROR) { + nslog_filter_unref($2); + YYABORT ; + } nslog_filter_unref($2); } ; @@ -186,7 +215,7 @@ filter: toplevel: filter { - $$ = *output = $1; + $$ = *output = nslog_filter_ref($1); } | error diff --git a/test/basictests.c b/test/basictests.c index a9b8ab0..b03bd7b 100644 --- a/test/basictests.c +++ b/test/basictests.c @@ -279,9 +279,11 @@ END_TEST START_TEST (test_nslog_parse_and_sprintf) { - nslog_filter_t *filt; + nslog_filter_t *filt = NULL; fail_unless(nslog_filter_from_text("cat:test", &filt) == NSLOG_NO_ERROR, "Unable to parse cat:test"); + fail_unless(filt != NULL, + "Strange, despite parsing okay, filt was NULL"); char *ct = nslog_filter_sprintf(filt); nslog_filter_unref(filt); fail_unless(strcmp(ct, "cat:test") == 0, -- cgit v1.2.3