org.ice4j.attribute: fix bytes conversion bugs (#67)

http://findbugs.sourceforge.net/bugDescriptions.html#BIT_IOR_OF_SIGNED_BYTE
http://findbugs.sourceforge.net/bugDescriptions.html#BIT_ADD_OF_SIGNED_BYTE

Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
This commit is contained in:
champtar 2016-04-20 22:02:15 +02:00 committed by Ingo Bauersachs
parent ce4126701e
commit 08f6ee8c64
3 changed files with 8 additions and 7 deletions

View File

@ -54,10 +54,10 @@ public class AttributeDecoder
}
//Discover attribute type
char attributeType = (char)((bytes[offset] << 8) | bytes[offset + 1]);
int len1 = bytes[offset + 2] & 0xff;
int len2 = bytes[offset + 3] & 0xff;
char attributeLength = (char)((len1 << 8) | len2);
char attributeType = (char)
(((bytes[offset] & 0xFF) << 8) | (bytes[offset + 1] & 0xFF));
char attributeLength = (char)
(((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF));
if(attributeLength > bytes.length - offset )
throw new StunException( StunException.ILLEGAL_ARGUMENT,

View File

@ -282,7 +282,8 @@ public class MessageIntegrityAttribute
binValue[3] = (byte)(getDataLength() & 0x00FF);
byte[] key = null;
char msgType = (char)((content[0] << 8) + content[1]);
char msgType =
(char) (((content[0] & 0xFF) << 8) | (content[1] & 0xFF));
if(Message.isRequestType(msgType))
{

View File

@ -229,8 +229,8 @@ public class UnknownAttributesAttribute extends Attribute
char originalOffset = offset;
for(int i = offset; i < originalOffset + length; i += 2)
{
char attributeID = (char)( (attributeValue[offset++] << 8) |
(attributeValue[offset++]) );
char attributeID = (char) (((attributeValue[offset++] & 0xFF) << 8)
| (attributeValue[offset++] & 0xFF));
addAttributeID(attributeID);
}
}