From d347480a1898155fda11ad14323d5dc67344f2c3 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 2 Sep 2010 22:18:14 -0700 Subject: [PATCH] Fix buffer compacting in NativeDaemonConnector The buffer was being compacted in the read loop, but the start offset on the compacted buffer wasn't being considered after the next read. Bug: 2501075 Change-Id: I163297d751cf800d0bbc66df66b1a0fa0785de49 --- .../java/com/android/server/NativeDaemonConnector.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/java/com/android/server/NativeDaemonConnector.java b/services/java/com/android/server/NativeDaemonConnector.java index c45259064c..f3cb9b7828 100644 --- a/services/java/com/android/server/NativeDaemonConnector.java +++ b/services/java/com/android/server/NativeDaemonConnector.java @@ -109,6 +109,10 @@ final class NativeDaemonConnector implements Runnable { int count = inputStream.read(buffer, start, BUFFER_SIZE - start); if (count < 0) break; + // Add our starting point to the count and reset the start. + count += start; + start = 0; + for (int i = 0; i < count; i++) { if (buffer[i] == 0) { String event = new String(buffer, start, i - start); @@ -140,6 +144,9 @@ final class NativeDaemonConnector implements Runnable { start = i + 1; } } + + // We should end at the amount we read. If not, compact then + // buffer and read again. if (start != count) { final int remaining = BUFFER_SIZE - start; System.arraycopy(buffer, start, buffer, 0, remaining);