Avoid one case of getting out of synch and trying to read too much.
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / FcpUtils.java
index 0957083..26a407c 100644 (file)
@@ -110,8 +110,8 @@ public class FcpUtils {
        }
 
        /**
-        * Tries to parse the given string into an int, returning <code>-1</code> if
-        * the string can not be parsed.
+        * Tries to parse the given string into an int, returning <code>-1</code>
+        * if the string can not be parsed.
         *
         * @param value
         *            The string to parse
@@ -268,7 +268,9 @@ public class FcpUtils {
                                throw new EOFException("stream reached eof");
                        }
                        destination.write(buffer, 0, read);
-                       remaining -= read;
+                       if (remaining > 0) {
+                               remaining -= read;
+                       }
                }
        }