summaryrefslogtreecommitdiffstats
path: root/stdlib/marshal.ml
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/marshal.ml')
-rw-r--r--stdlib/marshal.ml8
1 files changed, 4 insertions, 4 deletions
diff --git a/stdlib/marshal.ml b/stdlib/marshal.ml
index e248c468d..ffe397dec 100644
--- a/stdlib/marshal.ml
+++ b/stdlib/marshal.ml
@@ -26,7 +26,7 @@ external to_buffer_unsafe:
= "output_value_to_buffer"
let to_buffer buff ofs len v flags =
- if ofs < 0 || len < 0 || ofs + len > String.length buff
+ if ofs < 0 || len < 0 || ofs > String.length buff - len
then invalid_arg "Marshal.to_buffer: substring out of bounds"
else to_buffer_unsafe buff ofs len v flags
@@ -36,17 +36,17 @@ external data_size_unsafe: string -> int -> int = "marshal_data_size"
let header_size = 20
let data_size buff ofs =
- if ofs < 0 || ofs + header_size > String.length buff
+ if ofs < 0 || ofs > String.length buff - header_size
then invalid_arg "Marshal.data_size"
else data_size_unsafe buff ofs
let total_size buff ofs = header_size + data_size buff ofs
let from_string buff ofs =
- if ofs < 0 || ofs + header_size > String.length buff
+ if ofs < 0 || ofs > String.length buff - header_size
then invalid_arg "Marshal.from_size"
else begin
let len = data_size_unsafe buff ofs in
- if ofs + header_size + len > String.length buff
+ if ofs > String.length buff - (header_size + len)
then invalid_arg "Marshal.from_string"
else from_string_unsafe buff ofs
end