X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=cmd%2Fitest.c;h=fd6f4166f16cf1dad96a681892ce5f96b3fc0352;hb=b4f901042807e59061a862adc265d8f899b2243f;hp=fb4d797e43d78b56b4a466a7d086bfcdb20cdf14;hpb=986fe378172fa4bd5be1432ab2f8f7c2b1c43bae;p=u-boot diff --git a/cmd/itest.c b/cmd/itest.c index fb4d797e43..fd6f4166f1 100644 --- a/cmd/itest.c +++ b/cmd/itest.c @@ -1,8 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2003 * Tait Electronics Limited, Christchurch, New Zealand - * - * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -65,13 +64,13 @@ static long evalexp(char *s, int w) } switch (w) { case 1: - l = (long)(*(unsigned char *)buf); + l = (long)(*(u8 *)buf); break; case 2: - l = (long)(*(unsigned short *)buf); + l = (long)(*(u16 *)buf); break; case 4: - l = (long)(*(unsigned long *)buf); + l = (long)(*(u32 *)buf); break; } unmap_physmem(buf, w); @@ -80,7 +79,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) @@ -100,7 +100,7 @@ static char * evalstr(char *s) i++; } s[i] = 0; - return getenv((const char *)&s[2]); + return env_get((const char *)&s[2]); } else { return s; }