shitala099 / microemu

Automatically exported from code.google.com/p/microemu
0 stars 0 forks source link

BufferOverflowException on correct datagram #98

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
On writing the data to the datagram the exception occurs when the data length 
is exactly the size of the datagram:

    DatagramConnection con = (DatagramConnection) Connector.open("datagram://127.0.0.1:1234");
    Datagram datagram = con.newDatagram(10);
    datagram.reset();
    datagram.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

causes

java.nio.BufferOverflowException
    at org.microemu.cldc.datagram.DatagramImpl$BufferOutputStream.write(DatagramImpl.java:81)
    at java.io.OutputStream.write(OutputStream.java:99)
    at java.io.DataOutputStream.write(DataOutputStream.java:90)
    at java.io.FilterOutputStream.write(FilterOutputStream.java:80)
    at org.microemu.cldc.datagram.DatagramImpl.write(DatagramImpl.java:248)

For me, it looks like this is the problem

DatagramImpl.java:80:
    if (offset == buffer.length - 1) {
        throw new BufferOverflowException();
    }
should be
    if (offset > buffer.length - 1) {
        throw new BufferOverflowException();
    }

Microemu 2.0.4.

Original issue reported on code.google.com by przemysl...@gmail.com on 31 May 2011 at 2:15

GoogleCodeExporter commented 8 years ago
Fixed in trunk

Original comment by bar...@gmail.com on 17 Jun 2011 at 11:27