From 977af04a174a6b8af06309427477d5ddd9e9d583 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 4 Sep 2018 13:22:59 +1200 Subject: Fix buffer search utility --- src/org/traccar/helper/BufferUtil.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') 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; } } -- cgit v1.2.3