[prev in list] [next in list] [prev in thread] [next in thread]
List: jacorb-bugs
Subject: [jacorb-bugs] [Bug 501] New: Bad use of '+' instead of '|' to
From: bugzilla-daemon () inf ! fu-berlin ! de
Date: 2004-07-10 1:43:21
Message-ID: E1Bj6td-0003cQ-00 () berners ! inf ! fu-berlin ! de
[Download RAW message or body]
http://www.jacorb.org/cgi-bin/bugzilla/show_bug.cgi?id=501
Summary: Bad use of '+' instead of '|' to convert byte[] to int
Product: JacORB
Version: 2.2
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: ORB
AssignedTo: gerald.brose@acm.org
ReportedBy: jjowdy@levanta.com
QAContact: jacorb-bugs@lists.spline.inf.fu-berlin.de
This affects at least these two files:
org/jacorb/orb/giop/Messages.java
org/jacorb/orb/CDRInputStream.java
E.g., Messages::readULong(...)
{
if( little_endian )
{
return (( (buf[pos+3] & 0xff) << 24) +
( (buf[pos+2] & 0xff) << 16) +
( (buf[pos+1] & 0xff) << 8) +
( (buf[pos] & 0xff) << 0));
}
else //big endian
{
return (( (buf[pos] & 0xff) << 24) +
( (buf[pos+1] & 0xff) << 16) +
( (buf[pos+2] & 0xff) << 8) +
( (buf[pos+3] & 0xff) << 0));
}
}
If little endian and the top bit of buf[pos+3] is set, or if big endian and top
bit of buf[pos] is set, you'll get incorrect results.
Compare with this code to see why:
public class IntTest
{
public static void main(String[] args)
{
byte[] bytes = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF };
System.out.println(0xFFFFFFFF);
System.out.println(
(bytes[0] << 24) |
(bytes[1] << 16) |
(bytes[2] << 8) |
(bytes[3] << 0)
);
System.out.println(
(bytes[0] << 24) +
(bytes[1] << 16) +
(bytes[2] << 8) +
(bytes[3] << 0)
);
}
}
------- You are receiving this mail because: -------
You are the QA contact for the bug, or are watching the QA contact.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic