From 0eebe98ec68d9676c3f615eab656500155f77d91 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 15 Nov 2012 12:25:55 +0300 Subject: [PATCH] sval: ranges: set correct max in cast_rl() If the max value is higher than the type max then we set the casted max to the type max. Before if you assigned an unsigned int to a signed int, it was casting u32max to (-1) and using that as the max instead of s32max. Signed-off-by: Dan Carpenter --- smatch_ranges.c | 4 ++++ validation/sm_casts3.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 validation/sm_casts3.c diff --git a/smatch_ranges.c b/smatch_ranges.c index 4d595fd3..65b6ca1e 100644 --- a/smatch_ranges.c +++ b/smatch_ranges.c @@ -649,6 +649,10 @@ struct range_list *cast_rl(struct symbol *type, struct range_list *rl) if (type_signed(type) && sval_cmp(rl_max(rl), sval_type_max(type)) > 0) set_min = 1; + if (sval_positive_bits(rl_max(rl)) > type_positive_bits(type) && + sval_cmp(rl_max(rl), sval_type_max(type)) > 0) + set_max = 1; + FOR_EACH_PTR(rl, tmp) { sval_t min, max; diff --git a/validation/sm_casts3.c b/validation/sm_casts3.c new file mode 100644 index 00000000..fa42bb14 --- /dev/null +++ b/validation/sm_casts3.c @@ -0,0 +1,20 @@ +#include "check_debug.h" + +unsigned int a; +int b; +int func(void) +{ + b = a; + __smatch_implied(a); + __smatch_implied(b); +} + +/* + * check-name: smatch: casts #3 + * check-command: smatch -I.. sm_casts3.c + * + * check-output-start +sm_casts3.c:8 func() implied: a = '' +sm_casts3.c:9 func() implied: b = 's32min-s32max' + * check-output-end + */ -- 2.11.4.GIT