From: Andy Shevchenko Date: Fri, 10 Feb 2017 15:59:15 +0300 Subject: [U-Boot] [PATCH v1] cmd: itest: correct calculus for long format Message-ID: <20170210125915.73744-1-andriy.shevchenko@linux.intel.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Sebastien Colleur itest shell command doesn't work correctly in long format when doing comparaison due to wrong mask value calculus that overflow on 32 bits values. Signed-off-by: Sebastien Colleur --- cmd/itest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/itest.c b/cmd/itest.c index 60626c7fe9..e1896d9f97 100644 --- a/cmd/itest.c +++ b/cmd/itest.c @@ -80,7 +80,8 @@ static long evalexp(char *s, int w) l = simple_strtoul(s, NULL, 16); } - return l & ((1UL << (w * 8)) - 1); + /* avoid overflow on mask calculus */ + return (w >= sizeof(long)) ? l : (l & ((1UL << (w * 8)) - 1)); } static char * evalstr(char *s) -- 2.11.0