[U-Boot] [PATCH 2/2] 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 --- common/cmd_itest.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/common/cmd_itest.c b/common/cmd_itest.c index 5b301bf..6e1079c 100644 --- a/common/cmd_itest.c +++ b/common/cmd_itest.c @@ -66,16 +66,19 @@ op_tbl_t op_table [] = {
static long evalexp(char *s, int w) { - long l, *p; + long l = 0 + long *p;
/* if the parameter starts with a * then assume is a pointer to the value we want */ if (s[0] == '*') { p = (long *)simple_strtoul(&s[1], NULL, 16); - l = *p; + switch (w) { + case 1: return((long)(*(unsigned char *)p)); + case 2: return((long)(*(unsigned short *)p)); + case 4: return(*p); } else { l = simple_strtoul(s, NULL, 16); } - return (l & ((1 << (w * 8)) - 1)); }

Hi Frans,
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
common/cmd_itest.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/common/cmd_itest.c b/common/cmd_itest.c index 5b301bf..6e1079c 100644 --- a/common/cmd_itest.c +++ b/common/cmd_itest.c @@ -66,16 +66,19 @@ op_tbl_t op_table [] = {
static long evalexp(char *s, int w) {
- long l, *p;
- long l = 0
- long *p;
It takes chuzpe to send patches that do not even compile ;) Who ate the ';'?
/* if the parameter starts with a * then assume is a pointer to the value we want */ if (s[0] == '*') { p = (long *)simple_strtoul(&s[1], NULL, 16);
l = *p;
switch (w) {
case 1: return((long)(*(unsigned char *)p));
case 2: return((long)(*(unsigned short *)p));
case 4: return(*p);
The switch statement needs to be closed also.
} else { l = simple_strtoul(s, NULL, 16); }
- return (l & ((1 << (w * 8)) - 1));
}
Once you fix the syntax errors -
Acked-by: Detlev Zundel dzu@denx.de
Cheers Detlev
participants (2)
-
Detlev Zundel
-
Frans Meulenbroeks