Reverse the size check

I'm unsure how it would handle zero-size buffers if size==pos and no one
would need those anyway.
This commit is contained in:
Niklas Larsson 2020-07-04 11:37:37 +02:00
parent ce3096f919
commit 862bbeb308

View File

@ -297,12 +297,12 @@ concatBuffers xs
export
splitBuffer : HasIO io => Buffer -> Int -> io (Maybe (Buffer, Buffer))
splitBuffer buf pos = do size <- rawSize buf
if pos > size
then pure Nothing
else do Just first <- newBuffer pos
if pos > 0 && pos < size
then do Just first <- newBuffer pos
| Nothing => pure Nothing
Just second <- newBuffer (size - pos)
| Nothing => pure Nothing
copyData buf 0 pos first 0
copyData buf pos (size-pos) second 0
pure $ Just (first, second)
else pure Nothing