cmd: itest: correct calculus for long format
authorSebastien Colleur <sebastienx.colleur@intel.com>
Fri, 10 Feb 2017 12:59:15 +0000 (15:59 +0300)
committerTom Rini <trini@konsulko.com>
Fri, 17 Mar 2017 18:15:10 +0000 (14:15 -0400)
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 <sebastienx.colleur@intel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/itest.c

index 60626c7fe9c3d983d247aeee6f89b76548a189b5..e1896d9f9728df3f8195d6d4a11321c5f67723b1 100644 (file)
@@ -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)