From b5fff0cff93423196c4556dbf22958d08d195143 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sun, 31 May 2009 18:31:50 +0300 Subject: [PATCH] Fix overlapping ranges. Sometimes we add a range that overlaps with two or more existing ranges. The old way only modified the first range, but with this change we check the next ranges as well. I don't know that this bug caused any problems, but it made the debug output look a bit odd sometimes. Signed-off-by: Dan Carpenter --- smatch_ranges.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/smatch_ranges.c b/smatch_ranges.c index 2779940f..ec1077a1 100644 --- a/smatch_ranges.c +++ b/smatch_ranges.c @@ -129,8 +129,27 @@ void add_range(struct range_list **list, long long min, long long max) { struct data_range *tmp = NULL; struct data_range *new; + int check_next = 0; FOR_EACH_PTR(*list, tmp) { + if (check_next) { + /* Sometimes we overlap with more than one range + so we have to delete or modify the next range. */ + + /* Doesn't overlap with the next one. */ + if (max < tmp->min) + return; + /* Partially overlaps with the next one. */ + if (max < tmp->max) { + tmp->min = max + 1; + return; + } + /* Completely overlaps with the next one. */ + if (max > tmp->max) { + DELETE_CURRENT_PTR(tmp); + continue; + } + } if (max != whole_range.max && max + 1 == tmp->min) { /* join 2 ranges into a big range */ new = alloc_range(min, tmp->max); @@ -145,9 +164,12 @@ void add_range(struct range_list **list, long long min, long long max) if (min < tmp->min) { /* new range partially below */ if (max < tmp->max) max = tmp->max; + else + check_next = 1; new = alloc_range(min, max); REPLACE_CURRENT_PTR(tmp, new); - return; + if (!check_next) + return; } if (max <= tmp->max) /* new range already included */ return; @@ -155,15 +177,17 @@ void add_range(struct range_list **list, long long min, long long max) min = tmp->min; new = alloc_range(min, max); REPLACE_CURRENT_PTR(tmp, new); - return; + check_next = 1; } if (min != whole_range.min && min - 1 == tmp->max) { /* join 2 ranges into a big range */ new = alloc_range(tmp->min, max); REPLACE_CURRENT_PTR(tmp, new); - return; + check_next = 1; } } END_FOR_EACH_PTR(tmp); + if (check_next) + return; new = alloc_range(min, max); add_ptr_list(list, new); } -- 2.11.4.GIT