summaryrefslogtreecommitdiff
path: root/stdlib/lexing.ml
diff options
context:
space:
mode:
authorJacques Garrigue <garrigue at math.nagoya-u.ac.jp>2002-04-18 07:00:34 +0000
committerJacques Garrigue <garrigue at math.nagoya-u.ac.jp>2002-04-18 07:00:34 +0000
commit3447e059f033e7d59b4262fe869115aae20bcb85 (patch)
treeec3442ebc0940aefd4d6ab0e67dd88c08d5f5496 /stdlib/lexing.ml
parent059d9fc181595b6cf7d2d1a6472eb97fce1fe86a (diff)
downloadocaml-poly_meth2.tar.gz
merging poly_meth2poly_meth2
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/poly_meth2@4692 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'stdlib/lexing.ml')
-rw-r--r--stdlib/lexing.ml9
1 files changed, 7 insertions, 2 deletions
diff --git a/stdlib/lexing.ml b/stdlib/lexing.ml
index 8307c6f624..baba74ef4e 100644
--- a/stdlib/lexing.ml
+++ b/stdlib/lexing.ml
@@ -60,8 +60,13 @@ let lex_refill read_fun aux_buffer lexbuf =
(lexbuf.lex_buffer_len - lexbuf.lex_start_pos)
end else begin
(* We must grow the buffer. Doubling its size will provide enough
- space since n <= String.length aux_buffer <= String.length buffer *)
- let newbuf = String.create (2 * String.length lexbuf.lex_buffer) in
+ space since n <= String.length aux_buffer <= String.length buffer.
+ Watch out for string length overflow, though. *)
+ let newlen =
+ min (2 * String.length lexbuf.lex_buffer) Sys.max_string_length in
+ if lexbuf.lex_buffer_len - lexbuf.lex_start_pos + n > newlen
+ then failwith "Lexing.lex_refill: cannot grow buffer";
+ let newbuf = String.create newlen in
(* Copy the valid data to the beginning of the new buffer *)
String.blit lexbuf.lex_buffer lexbuf.lex_start_pos
newbuf 0