peter-lawrey / Java-Chronicle

Java Indexed Record Chronicle
1.22k stars 193 forks source link

incorrect pointer math in AbstractExcerpt.position() #6

Closed vlad-ilyushchenko closed 12 years ago

vlad-ilyushchenko commented 12 years ago

i noticed that skipBytes() doesn't work correctly, it turned out to be a problem with position(). this code works:

@Override
public Excerpt position(int position) {
    if (position < 0 || position >= capacity()) throw new IndexOutOfBoundsException();
    this.position = start + position; // start has to be added
    return this;
}
peter-lawrey commented 12 years ago

I will fix this soon.

peter-lawrey commented 12 years ago

Can you provide a unit test which fails currently?

vlad-ilyushchenko commented 12 years ago

It isn't a unit test per se, this code prompted me to have a look:

    Excerpt excerpt = currentTsc.createExcerpt();
    try {
        excerpt.index(index);
        excerpt.skipBytes(offset);
        return excerpt.readInt();
    } finally {
        excerpt.finish();
    }

After excerpt.index() call position field is set to a rather large offset and is reset to "offset" value when skipBytes() is called.

Cheers, Vlad

-----Original Message----- From: Peter Lawrey [mailto:reply@reply.github.com] Sent: 26 March 2012 10:01 To: Ilyuschenko, Vlad Subject: Re: [Java-Chronicle] incorrect pointer math in AbstractExcerpt.position() (#6)

Can you provide a unit test which fails currently?


Reply to this email directly or view it on GitHub: https://github.com/peter-lawrey/Java-Chronicle/issues/6#issuecomment-4690170

peter-lawrey commented 12 years ago

Fixed now