diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/helper/BufferUtil.java | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/org/traccar/helper/BufferUtil.java b/src/org/traccar/helper/BufferUtil.java index 5606dba8a..15c619ec5 100644 --- a/src/org/traccar/helper/BufferUtil.java +++ b/src/org/traccar/helper/BufferUtil.java @@ -37,10 +37,11 @@ public final class BufferUtil { } public static int indexOf(String needle, ByteBuf haystack, int startIndex, int endIndex) { - haystack = Unpooled.wrappedBuffer(haystack); - haystack.readerIndex(startIndex); - haystack.writerIndex(endIndex); - return indexOf(needle, haystack); + ByteBuf wrappedHaystack = Unpooled.wrappedBuffer(haystack); + wrappedHaystack.readerIndex(startIndex - haystack.readerIndex()); + wrappedHaystack.writerIndex(endIndex - haystack.readerIndex()); + int result = indexOf(needle, wrappedHaystack); + return result < 0 ? result : haystack.readerIndex() + result; } } |