Skip to contentSkip to conversation

cmd_itest.c: fix pointer dereferencing

PATCH New Frans Meulenbroeks 2 participants 2 messages Feb 20, 2010 – Feb 22, 2010

lore
Share & tools
lore
#0 lore raw

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.

---
 common/cmd_itest.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
common/cmd_itest.c +6 -3
index 5b301bf..6e1079c 100644
@@ -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));
 }
 
Signature · 1 line
1.6.4.2
#1 lore raw

PATCH 2/2 cmd_itest.c: fix pointer dereferencing

Hi Frans,

Quoted 13 lines

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

---
 common/cmd_itest.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
common/cmd_itest.c +0 -0
index 5b301bf..6e1079c 100644

common/cmd_itest.c op_tbl_t op_table [] = { · line 70

Quoted 6 lines
common/cmd_itest.c +2 -1
@@ -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 ';'?

common/cmd_itest.c op_tbl_t op_table [] = { · line 78

Quoted 9 lines
common/cmd_itest.c +4 -1
 	/* 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.

common/cmd_itest.c op_tbl_t op_table [] = { · line 83

Quoted 6 lines
common/cmd_itest.c +0 -1
 	} else {
 		l = simple_strtoul(s, NULL, 16);
 	}
-
 	return (l & ((1 << (w * 8)) - 1));
 }

Once you fix the syntax errors -

Cheers
Detlev

Signature · 8 lines
   "Our enemies  are innovative  and resourceful, and so are we.  They
never stop thinking about new ways to harm our country and our people,
and neither do we."
       -- George W. Bush during a defense bill ceremony on 5. Aug 2004
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de