summaryrefslogtreecommitdiffstats
path: root/stdlib/string.ml
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/string.ml')
-rw-r--r--stdlib/string.ml8
1 files changed, 4 insertions, 4 deletions
diff --git a/stdlib/string.ml b/stdlib/string.ml
index 2cdb83b34..6f2495c7e 100644
--- a/stdlib/string.ml
+++ b/stdlib/string.ml
@@ -38,7 +38,7 @@ let copy s =
r
let sub s ofs len =
- if ofs < 0 || len < 0 || ofs + len > length s
+ if ofs < 0 || len < 0 || ofs > length s - len
then invalid_arg "String.sub"
else begin
let r = create len in
@@ -47,13 +47,13 @@ let sub s ofs len =
end
let fill s ofs len c =
- if ofs < 0 || len < 0 || ofs + len > length s
+ if ofs < 0 || len < 0 || ofs > length s - len
then invalid_arg "String.fill"
else unsafe_fill s ofs len c
let blit s1 ofs1 s2 ofs2 len =
- if len < 0 || ofs1 < 0 || ofs1 + len > length s1
- || ofs2 < 0 || ofs2 + len > length s2
+ if len < 0 || ofs1 < 0 || ofs1 > length s1 - len
+ || ofs2 < 0 || ofs2 > length s2 - len
then invalid_arg "String.blit"
else unsafe_blit s1 ofs1 s2 ofs2 len