From 2f97139ceab4b677c912fb96106400048ad57f0a Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 13 Apr 2018 16:52:29 +0200 Subject: segtree: Fix for last elem at interval end Unclosed interval check at end of interval_map_decompose() missed to check whether interval start is the last possible element in given set before creating a range expression. This led to the last element incorrectly printed as range from itself to itself. Fix this by comparing the upper boundary against the lower one. In order to keep indenting level low, invert the entry check and jump to the end if it matches. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/segtree.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/segtree.c b/src/segtree.c index 1970265a..5939d8fc 100644 --- a/src/segtree.c +++ b/src/segtree.c @@ -857,21 +857,25 @@ void interval_map_decompose(struct expr *set) expr_free(i); } - /* Unclosed interval */ - if (low != NULL) { - i = constant_expr_alloc(&low->location, low->dtype, - low->byteorder, expr_value(low)->len, - NULL); - mpz_init_bitmask(i->value, i->len); + if (!low) /* no unclosed interval at end */ + goto out; + i = constant_expr_alloc(&low->location, low->dtype, + low->byteorder, expr_value(low)->len, NULL); + mpz_init_bitmask(i->value, i->len); + + if (!mpz_cmp(i->value, expr_value(low)->value)) { + expr_free(i); + i = low; + } else { i = range_expr_alloc(&low->location, expr_value(low), i); i = set_elem_expr_alloc(&low->location, i); if (low->ops->type == EXPR_MAPPING) i = mapping_expr_alloc(&i->location, i, low->right); - - compound_expr_add(set, i); } + compound_expr_add(set, i); +out: mpz_clear(range); mpz_clear(p); -- cgit v1.2.3