Commit f3651764e57e353251695691677bd95ba5a420bc

Authored by Frans Meulenbroeks
Committed by Wolfgang Denk
1 parent 0ad22703f0

cmd_itest.c: fix pointer dereferencing

fix pointer dereferencing
if the size is .b and .w an 8 or 16 bit access is done.

Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>

Showing 1 changed file with 7 additions and 2 deletions Side-by-side Diff

... ... @@ -66,12 +66,17 @@
66 66  
67 67 static long evalexp(char *s, int w)
68 68 {
69   - long l, *p;
  69 + long l = 0;
  70 + long *p;
70 71  
71 72 /* if the parameter starts with a * then assume is a pointer to the value we want */
72 73 if (s[0] == '*') {
73 74 p = (long *)simple_strtoul(&s[1], NULL, 16);
74   - l = *p;
  75 + switch (w) {
  76 + case 1: return((long)(*(unsigned char *)p));
  77 + case 2: return((long)(*(unsigned short *)p));
  78 + case 4: return(*p);
  79 + }
75 80 } else {
76 81 l = simple_strtoul(s, NULL, 16);
77 82 }