From a1684b4177a9b2991a90f26147db39a180387831 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 17 Jan 2013 23:43:22 +0300 Subject: [PATCH] sval: introduce sval_min/max() Returns the larger or smaller of the two values. Signed-off-by: Dan Carpenter --- smatch.h | 2 ++ smatch_sval.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/smatch.h b/smatch.h index a31b78a4..5392c168 100644 --- a/smatch.h +++ b/smatch.h @@ -554,6 +554,8 @@ int sval_is_a_max(sval_t sval); int sval_cmp(sval_t one, sval_t two); int sval_cmp_t(struct symbol *type, sval_t one, sval_t two); int sval_cmp_val(sval_t one, long long val); +sval_t sval_min(sval_t one, sval_t two); +sval_t sval_max(sval_t one, sval_t two); int sval_too_low(struct symbol *type, sval_t sval); int sval_too_high(struct symbol *type, sval_t sval); int sval_fits(struct symbol *type, sval_t sval); diff --git a/smatch_sval.c b/smatch_sval.c index f3c2a19f..7a70c8cd 100644 --- a/smatch_sval.c +++ b/smatch_sval.c @@ -213,6 +213,20 @@ int sval_cmp_val(sval_t one, long long val) return sval_cmp(one, sval); } +sval_t sval_min(sval_t one, sval_t two) +{ + if (sval_cmp(one, two) > 0) + return two; + return one; +} + +sval_t sval_max(sval_t one, sval_t two) +{ + if (sval_cmp(one, two) < 0) + return two; + return one; +} + int sval_too_low(struct symbol *type, sval_t sval) { if (sval_is_negative(sval) && type_unsigned(type)) -- 2.11.4.GIT