public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 2/2] cmd_itest.c: fix pointer dereferencing
@ 2010-02-20 11:23 Frans Meulenbroeks
  2010-02-22 11:59 ` Detlev Zundel
  0 siblings, 1 reply; 5+ messages in thread
From: Frans Meulenbroeks @ 2010-02-20 11:23 UTC (permalink / raw)
  To: u-boot

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));
 }
 
-- 
1.6.4.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH 2/2] cmd_itest.c: fix pointer dereferencing
  2010-02-20 11:23 [U-Boot] [PATCH 2/2] cmd_itest.c: fix pointer dereferencing Frans Meulenbroeks
@ 2010-02-22 11:59 ` Detlev Zundel
  0 siblings, 0 replies; 5+ messages in thread
From: Detlev Zundel @ 2010-02-22 11:59 UTC (permalink / raw)
  To: u-boot

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

-- 
   "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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH 2/2] cmd_itest.c: fix pointer dereferencing
@ 2010-02-22 21:49 Frans Meulenbroeks
  2010-02-23 11:37 ` Detlev Zundel
  2010-02-23 23:09 ` Wolfgang Denk
  0 siblings, 2 replies; 5+ messages in thread
From: Frans Meulenbroeks @ 2010-02-22 21:49 UTC (permalink / raw)
  To: u-boot

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, 7 insertions(+), 2 deletions(-)

diff --git a/common/cmd_itest.c b/common/cmd_itest.c
index 5b301bf..58c5e7b 100644
--- a/common/cmd_itest.c
+++ b/common/cmd_itest.c
@@ -66,12 +66,17 @@ 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);
 	}
-- 
1.6.4.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH 2/2] cmd_itest.c: fix pointer dereferencing
  2010-02-22 21:49 Frans Meulenbroeks
@ 2010-02-23 11:37 ` Detlev Zundel
  2010-02-23 23:09 ` Wolfgang Denk
  1 sibling, 0 replies; 5+ messages in thread
From: Detlev Zundel @ 2010-02-23 11:37 UTC (permalink / raw)
  To: u-boot

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>

You could have included my previously given Acked-by.  But anyway:

Acked-by: Detlev Zundel <dzu@denx.de>

> ---
>  common/cmd_itest.c |    9 +++++++--
>  1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/common/cmd_itest.c b/common/cmd_itest.c
> index 5b301bf..58c5e7b 100644
> --- a/common/cmd_itest.c
> +++ b/common/cmd_itest.c
> @@ -66,12 +66,17 @@ 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);
>  	}

-- 
It's like manually inflatable airbags -- people will never
think to use it in time to actually get any help from it.
             -- Miles Bader in <20030607122005.GA1086@gnu.org>
--
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH 2/2] cmd_itest.c: fix pointer dereferencing
  2010-02-22 21:49 Frans Meulenbroeks
  2010-02-23 11:37 ` Detlev Zundel
@ 2010-02-23 23:09 ` Wolfgang Denk
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfgang Denk @ 2010-02-23 23:09 UTC (permalink / raw)
  To: u-boot

Dear Frans Meulenbroeks,

In message <1266875346-17025-1-git-send-email-fransmeulenbroeks@gmail.com> you wrote:
> 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, 7 insertions(+), 2 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"We learn from history that we learn nothing from history."
- George Bernard Shaw

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-02-23 23:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-20 11:23 [U-Boot] [PATCH 2/2] cmd_itest.c: fix pointer dereferencing Frans Meulenbroeks
2010-02-22 11:59 ` Detlev Zundel
  -- strict thread matches above, loose matches on Subject: below --
2010-02-22 21:49 Frans Meulenbroeks
2010-02-23 11:37 ` Detlev Zundel
2010-02-23 23:09 ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox