Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect decoding of short optional attributes #8

Closed
GoogleCodeExporter opened this issue Oct 9, 2015 · 5 comments
Closed

Incorrect decoding of short optional attributes #8

GoogleCodeExporter opened this issue Oct 9, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Send a messages with a positive short (2-byte) attribute value with a
negative LSB
2. Check received value - it will be negative


What is the expected output? What do you see instead?
The received value is supposed to be the same as sent one

What version of the product are you using? On what operating system?
2.0b5

Please provide any additional information below.
This is an obvious bug in OctetUtils.bytesToShort(byte[] bytes, int offset)
(missed & 0xff) ; A similar code in OctetUtils.bytesToInt is correct

Original issue reported on code.google.com by igor.sko...@gmail.com on 30 Oct 2008 at 8:09

@GoogleCodeExporter
Copy link
Author

Can you give me the exact examples of the error. Code will be nice. I created 
some 
test for the OctetUtil (attached) but there is no problem found.

Original comment by uuda...@gmail.com on 30 Oct 2008 at 8:36

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

package org.jsmpp.util;

import junit.framework.TestCase;

public class OctetItilsTest extends TestCase{
    public void testShortEncode() {
        assertEquals(0x1D4, OctetUtil.bytesToShort(new byte[] {1, (byte)0xD4}, 0));
    }

}

junit.framework.AssertionFailedError: expected:<468> but was:<-44>
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.Assert.failNotEquals(Assert.java:280)
    at junit.framework.Assert.assertEquals(Assert.java:64)
    at junit.framework.Assert.assertEquals(Assert.java:198)
    at junit.framework.Assert.assertEquals(Assert.java:204)
    at org.jsmpp.util.OctetItilsTest.testShortEncode(OctetItilsTest.java:7)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestR
eference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)


Original comment by igor.sko...@gmail.com on 30 Oct 2008 at 8:50

@GoogleCodeExporter
Copy link
Author

A more prominent version:
assertEquals(0x1D4, 
OctetUtil.bytesToShort(OctetUtil.shortToBytes((short)0x1D4), 0));
with the same result:

junit.framework.AssertionFailedError: expected:<468> but was:<-44>

Original comment by igor.sko...@gmail.com on 30 Oct 2008 at 8:59

@GoogleCodeExporter
Copy link
Author

Thanks a lot Igor. The bug has been fixed. The fixed source has been attached 
or you 
can get it from the repository.

Original comment by uuda...@gmail.com on 30 Oct 2008 at 9:05

  • Changed state: Fixed

Attachments:

@GoogleCodeExporter
Copy link
Author

Thank you!

Original comment by igor.sko...@gmail.com on 30 Oct 2008 at 9:08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant