diff mbox

[U-Boot] Don't do an undefined 32-bit shift on a 32-bit value for a long (4 byte) itest.l command.

Message ID 46C0B30074A11D428385D0E8721CD0402B79B0A7@SV950-MBX2.corp.intusurg.com
State Changes Requested
Headers show

Commit Message

Joshua Radel June 15, 2011, 11:10 p.m. UTC
Without this fix, the following statement erroneously echoed "true" (at least on the microblaze architecture):
if itest.l 0 == 1; then echo "true"; else echo "false"; fi

(using itest.w or itest.b worked as expected even without this change)

Signed-off-by: Josh Radel <josh.radel_at_intusurg.com>
---
 common/cmd_itest.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
 mode change 100644 => 100755 common/cmd_itest.c

Comments

Mike Frysinger June 21, 2011, 6:39 p.m. UTC | #1
On Wed, Jun 15, 2011 at 19:10, Joshua Radel wrote:
> Without this fix, the following statement erroneously echoed "true" (at least on the microblaze architecture):
> if itest.l 0 == 1; then echo "true"; else echo "false"; fi
>
> (using itest.w or itest.b worked as expected even without this change)

the subject should read something like:
itest: avoid undefined C semantics with large shift values

> Signed-off-by: Josh Radel <josh.radel_at_intusurg.com>

your s-o-b tag is invalid.  you must have a proper e-mail address here.

>  mode change 100644 => 100755 common/cmd_itest.c

this is wrong.  i guess you're editing on a windows machine or
something.  no .c file should be executable.

> -       return (l & ((1 << (w * 8)) - 1));
> +       if (w < sizeof(long)) {
> +               return (l & ((1 << (w * 8)) - 1));
> +       } else {
> +               return (l);
> +       }

please add a comment as to why the sizeof(long) test is here.  i dont
think most people reading the code at a glance will grok what it's
doing.
-mike
diff mbox

Patch

diff --git a/common/cmd_itest.c b/common/cmd_itest.c
old mode 100644
new mode 100755
index 2a238a4..5f5ac4e
--- a/common/cmd_itest.c
+++ b/common/cmd_itest.c
@@ -79,7 +79,11 @@  static long evalexp(char *s, int w)
 		l = simple_strtoul(s, NULL, 16);
 	}
 
-	return (l & ((1 << (w * 8)) - 1));
+	if (w < sizeof(long)) {
+		return (l & ((1 << (w * 8)) - 1));
+	} else {
+		return (l);
+	}
 }
 
 static char * evalstr(char *s)