Fix overflow if more than two frames are queued
authorMicah Elizabeth Scott <micah@scanlime.org>
Sat, 8 Mar 2014 05:19:54 +0000 (21:19 -0800)
committerMicah Elizabeth Scott <micah@scanlime.org>
Sat, 8 Mar 2014 05:19:54 +0000 (21:19 -0800)
OpenPixelControl.pde

index 118eb2a56cf10a20b7e1cc3c229d3c77d435068e..830ba6c1b07a5812ab46b50c740dbc7491b2c8da 100644 (file)
@@ -46,9 +46,10 @@ class OpenPixelControl extends SCPattern {
                 bufferedByteCount = client.readBytes(buffer);
             } else {
                 // Append to an earlier partial frame
-                byte[] additional = client.readBytes();
-                arrayCopy(additional, 0, buffer, bufferedByteCount, additional.length);
-                bufferedByteCount += additional.length;
+                byte[] additional = new byte[buffer.length - bufferedByteCount];
+                int additionalLength = client.readBytes(additional);
+                arrayCopy(additional, 0, buffer, bufferedByteCount, additionalLength);
+                bufferedByteCount += additionalLength;
             }
 
             // Extract OPC packets from buffer