From d2ae6d6b2c1eaccc3d4603d1ee4e55916661deb6 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 15 Mar 2013 23:11:55 +0300 Subject: [PATCH] ranges: in cast_rl() sometimes it's better to just give up The story here is that sometime people give you a very bogus range like 1-0 and in that case cast_rl() should just return the whole range because it means we don't actually know anything. I've tested this for a while and it doesn't seem to cause too many problems. Signed-off-by: Dan Carpenter --- smatch_ranges.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/smatch_ranges.c b/smatch_ranges.c index c4d3291c..d2a70240 100644 --- a/smatch_ranges.c +++ b/smatch_ranges.c @@ -740,17 +740,30 @@ static int rl_is_sane(struct range_list *rl) type = rl_type(rl); FOR_EACH_PTR(rl, tmp) { - if (type != tmp->min.type || type != tmp->max.type) - return 0; if (!sval_fits(type, tmp->min)) return 0; if (!sval_fits(type, tmp->max)) return 0; + if (sval_cmp(tmp->min, tmp->max) > 0) + return 0; } END_FOR_EACH_PTR(tmp); return 1; } +static int rl_type_consistent(struct range_list *rl) +{ + struct data_range *tmp; + struct symbol *type; + + type = rl_type(rl); + FOR_EACH_PTR(rl, tmp) { + if (type != tmp->min.type || type != tmp->max.type) + return 0; + } END_FOR_EACH_PTR(tmp); + return 1; +} + struct range_list *cast_rl(struct symbol *type, struct range_list *rl) { struct data_range *tmp; @@ -759,7 +772,11 @@ struct range_list *cast_rl(struct symbol *type, struct range_list *rl) if (!rl) return NULL; - if (!type || (rl_is_sane(rl) && type == rl_type(rl))) + if (!type) + return rl; + if (!rl_is_sane(rl)) + return alloc_whole_rl(type); + if (type == rl_type(rl) && rl_type_consistent(rl)) return rl; FOR_EACH_PTR(rl, tmp) { -- 2.11.4.GIT