]> code.delx.au - offlineimap/blobdiff - src/Network/IMAP/Connection.hs
Test for failure in readLine and readBytes
[offlineimap] / src / Network / IMAP / Connection.hs
index ace53e85d82509a1fb071bd18713104e7752b487..998f0b550bf4af80a40bcd6f6f747d1d4f084129 100644 (file)
@@ -39,13 +39,15 @@ newStringConnection =
                     writeBytes = lwriteBytes,
                     closeConn = return ()}
     where 
-          lreadBytes count = 
-              do (s,sw) <- get
-                 if genericLength s < count
-                    then fail "EOF in input in readBytes"
-                    else do let (r, s') = genericSplitAt count s
-                            put (s', sw)
-                            return r
+          lreadBytes count
+              | count < 0 = fail "readBytes: negative count"
+              | otherwise =
+                  do (s,sw) <- get
+                     if genericLength s < count
+                       then fail "EOF in input in readBytes"
+                       else do let (r, s') = genericSplitAt count s
+                               put (s', sw)
+                               return r
           lreadLine =
               do (s, sw) <- get
                  let (line, remainder) = spanList (\x -> "\r\n" /= take 2 x) s