From: Alan T. DeKok Date: Tue, 7 Sep 2021 15:09:47 +0000 (-0400) Subject: sign promote the input only if the underlying data type is signed X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71438a18b3ef2caff56aa257b749b39288f94b06;p=thirdparty%2Ffreeradius-server.git sign promote the input only if the underlying data type is signed --- diff --git a/src/lib/util/value.c b/src/lib/util/value.c index 2409aa39a02..cd49a53def7 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -2831,9 +2831,15 @@ static inline int fr_value_box_cast_integer_to_integer(UNUSED TALLOC_CTX *ctx, f } min = fr_value_box_integer_min[dst_type]; - if ((min < 0) && SIGN_BIT_HIGH(tmp, len)) { - tmp = SIGN_PROMOTE(tmp, len); - if (((int64_t)tmp < min)) { + + /* + * Sign promote the input if the source type is + * signed, and the high bit is set. + */ + if (fr_value_box_integer_min[src->type] < 0) { + if (SIGN_BIT_HIGH(tmp, len)) tmp = SIGN_PROMOTE(tmp, len); + + if ((int64_t)tmp < min) { fr_strerror_printf("Invalid cast from %s to %s. %"PRId64" " "outside value range %"PRId64"-%"PRIu64, fr_table_str_by_value(fr_value_box_type_table, src->type, ""),