takebits/dropbits: check that n >= 0
authorRichard W.M. Jones <rich@annexia.org>
Wed, 4 Apr 2012 09:40:42 +0000 (09:40 +0000)
committerRichard W.M. Jones <rich@annexia.org>
Wed, 4 Apr 2012 09:40:42 +0000 (09:40 +0000)
http://code.google.com/p/bitstring/issues/detail?id=18

bitstring.ml

index 8a9ef3e..efac383 100644 (file)
@@ -136,11 +136,11 @@ let subbitstring (data, off, len) off' len' =
 let dropbits n (data, off, len) =
   let off = off + n in
   let len = len - n in
-  if len < 0 then invalid_arg "dropbits";
+  if len < 0 || n < 0 then invalid_arg "dropbits";
   (data, off, len)
 
 let takebits n (data, off, len) =
-  if len < n then invalid_arg "takebits";
+  if len < n || n < 0 then invalid_arg "takebits";
   (data, off, n)
 
 (*----------------------------------------------------------------------*)