X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cmd%2Fitest.c;h=e1896d9f9728df3f8195d6d4a11321c5f67723b1;hb=72fa58931e1e7feef7801b92671c545c7aca32f1;hp=91ae5c2704c882be8d4457d67d5f8488b19d2f1c;hpb=2218c54bc13c8045903afc05d1364439a230da1f;p=oweals%2Fu-boot.git diff --git a/cmd/itest.c b/cmd/itest.c index 91ae5c2704..e1896d9f97 100644 --- a/cmd/itest.c +++ b/cmd/itest.c @@ -59,19 +59,19 @@ static long evalexp(char *s, int w) if (s[0] == '*') { addr = simple_strtoul(&s[1], NULL, 16); buf = map_physmem(addr, w, MAP_WRBACK); - if (!buf) { + if (!buf && addr) { puts("Failed to map physical memory\n"); return 0; } 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 +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)