From 4ad0a6674d457e204d0b4ac59eb87cb195dec0ed Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 9 Nov 2014 13:47:36 +0100 Subject: [PATCH] store: Let NREGEX (!~) not match on NULL values. --- src/core/store_lookup.c | 4 +++- t/unit/core/store_lookup_test.c | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index e2ec1b1..eab37b4 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -322,7 +322,7 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj, if ((sdb_store_expr_eval(CMP_M(m)->left, obj, &v, filter)) || (sdb_data_isnull(&v))) - status = 0; + status = INT_MAX; else { char value[sdb_data_strlen(&v) + 1]; if (sdb_data_format(&v, value, sizeof(value), SDB_UNQUOTED) < 0) @@ -334,6 +334,8 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj, if (free_regex) regfree(®ex); sdb_data_free_datum(&v); + if (status == INT_MAX) + return 0; if (m->type == MATCHER_NREGEX) return !status; return status; diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 4d968a6..18d811f 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -576,12 +576,12 @@ START_TEST(test_scan) { "attribute['k1'] =~ '^v1$'", NULL, 1 }, { "attribute['k1'] =~ 'v'", NULL, 2 }, { "attribute['k1'] =~ '1'", NULL, 1 }, - { "attribute['k1'] !~ 'v'", NULL, 1 }, + { "attribute['k1'] !~ 'v'", NULL, 0 }, { "attribute['k1'] = 'v2'", NULL, 1 }, { "attribute['k1'] =~ 'v2'", NULL, 1 }, { "attribute['x1'] =~ 'v'", NULL, 0 }, { "attribute['x1'] =~ 'NULL'", NULL, 0 }, - { "attribute['x1'] !~ 'v'", NULL, 3 }, + { "attribute['x1'] !~ 'v'", NULL, 0 }, { "attribute['k1'] IS NULL", NULL, 1 }, { "attribute['x1'] IS NULL", NULL, 3 }, { "attribute['k1'] IS NOT NULL", NULL, 2 }, @@ -595,7 +595,7 @@ START_TEST(test_scan) { "attribute['k1'] != 'v1'", NULL, 1 }, { "attribute['k1'] != 'v2'", NULL, 1 }, { "ANY attribute != 'x' " - "AND attribute['y'] !~ 'x'", NULL, 2 }, + "AND attribute['k1'] !~ 'x'", NULL, 2 }, }; sdb_strbuf_t *errbuf = sdb_strbuf_create(64); -- 2.30.2