From e3ed3d332db66cf933650481f47832aaadb70ec3 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Tue, 14 Feb 2017 11:39:51 +0200 Subject: [PATCH] 7862 libdisasm: left shift of negative value Reviewed by: Vitaliy Gusev Reviewed by: Marcel Telka Reviewed by: Yuri Pankov Reviewed by: Robert Mustacchi Reviewed by: Dale Ghent Reviewed by: Jason King Reviewed by: Andrew Stormont Approved by: Dan McDonald --- usr/src/lib/libdisasm/common/dis_sparc_fmt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/usr/src/lib/libdisasm/common/dis_sparc_fmt.c b/usr/src/lib/libdisasm/common/dis_sparc_fmt.c index 017c056477..ceaafa47fe 100644 --- a/usr/src/lib/libdisasm/common/dis_sparc_fmt.c +++ b/usr/src/lib/libdisasm/common/dis_sparc_fmt.c @@ -32,6 +32,7 @@ #include +#include #include #if !defined(DIS_STANDALONE) @@ -647,7 +648,7 @@ static const char *prefetch_str[32] = { static void prt_field(const char *, uint32_t, int); static const char *get_regname(dis_handle_t *, int, uint32_t); -static int32_t sign_extend(int32_t, int32_t); +static int32_t sign_extend(int32_t, uint32_t); static void prt_name(dis_handle_t *, const char *, int); @@ -2203,12 +2204,13 @@ prt_field(const char *field, uint32_t val, int len) * integer */ static int32_t -sign_extend(int32_t val, int32_t bits) +sign_extend(int32_t val, uint32_t bits) { - if ((val & (1L << (bits - 1))) == 0) - return (val); + uint32_t mask; - return ((-1L << bits) | val); + ASSERT(bits > 0); + mask = 1L << (bits - 1); /* 2**(bits - 1) */ + return (-(val & mask) + (val & ~mask)); } /* -- 2.11.4.GIT