MantisBT - OCaml
View Issue Details
0004718OCamlocamldocpublic2009-02-16 09:152012-09-25 20:10
warren 
 
normalcrashalways
closedunable to reproduce 
3.10.2 
 
0004718: unterminated quote causes crash
If an ocamldoc-style comment contains an unterminated quote, a crash occurs when preprocessing the file, e.g.

(** hello " *)

Fatal error: exception Loc.Exc_located(_, _)
Raised at file "camlp4/Camlp4/Struct/Lexer.mll", line 186, characters 9-46
Called from file "camlp4/Camlp4/Struct/Lexer.mll", line 357, characters 12-54
Called from file "camlp4/Camlp4/Struct/Lexer.mll", line 155, characters 4-21
Called from file "camlp4/Camlp4/Struct/Lexer.mll", line 294, characters 26-63
Called from file "camlp4/Camlp4/Struct/Lexer.mll", line 454, characters 16-37
Called from file "stream.ml", line 78, characters 22-36
Called from file "stream.ml", line 111, characters 8-14
Called from file "build/optcomp/optcomp.ml", line 96, characters 42-48
Called from file "stream.ml", line 78, characters 22-36
Called from file "build/optcomp/pa_optcomp.ml", line 365, characters 47-53
Called from file "build/optcomp/pa_optcomp.ml", line 558, characters 26-38
Called from file "build/optcomp/pa_optcomp.ml", line 678, characters 48-57
Called from file "stream.ml", line 78, characters 22-36
Called from file "stream.ml", line 124, characters 10-19
Called from file "build/optcomp/optcomp.ml", line 111, characters 6-167
Re-raised at file "build/optcomp/optcomp.ml", line 96, characters 24-147
Called from file "build/optcomp/optcomp_o.ml", line 12, characters 21-23
Preprocessing error on file src/core/extlib/substring.mli
No tags attached.
Issue History
2009-02-16 09:15warrenNew Issue
2009-02-16 09:15warrenStatusnew => assigned
2009-02-16 09:15warrenAssigned To => ertai
2010-06-16 12:22ertaiAssigned Toertai => guesdon
2010-06-16 13:40guesdonNote Added: 0005560
2010-06-16 13:40guesdonAssigned Toguesdon =>
2010-06-16 13:41guesdonStatusassigned => feedback
2010-06-29 15:25aostruszkaNote Added: 0005572
2010-06-29 15:33aostruszkaNote Edited: 0005572
2011-01-17 14:37Camarade_TuxNote Added: 0005778
2012-02-16 09:20glonduNote Added: 0006929
2012-03-21 16:35xleroyNote Added: 0007125
2012-03-21 16:35xleroyStatusfeedback => resolved
2012-03-21 16:35xleroyResolutionopen => unable to reproduce
2012-09-25 20:10xleroyStatusresolved => closed
2017-02-23 16:46doligezCategoryOCamldoc => ocamldoc

Notes
(0005560)
guesdon   
2010-06-16 13:40   
Having an unterminated string in a comment is an ocaml error:

# cat > t.ml
(* "coucou le commentaire avec une mauvaise chaine *)
let x = 1;;
^D

#ocaml t.ml
File "t.ml", line 1, characters 0-2:
Error: This comment contains an unterminated string literal

This is not an ocamldoc related problem. The error occurs when calling the ocaml parser.
(0005572)
aostruszka   
2010-06-29 15:25   
(edited on: 2010-06-29 15:33)
Applies to both ocamlc and camlp4 (3.11.2)

$ cat dupa.ml
(* Some " to be printed *)
let () = print_char '"'; print_newline ();;

$ ocamlc dupa.ml
File "dupa.ml", line 1, characters 0-2:
Error: Comment not terminated

$ ocamlc -pp camlp4o dupa.ml
File "dupa.ml", line 1, characters 0-71 (end at line 3, character 0):
Comment not terminated
File "dupa.ml", line 1, characters 0-1:
Error: Preprocessor error

(0005778)
Camarade_Tux   
2011-01-17 14:37   
This also lead to the disappearance of code sometimes. I just had a whole chunk of a file that disappeared because of that behaviour.

        Objective Caml version 3.12.0

# (* a " a *)
  let x = 42 in
  (* b " b *)
  x;;
Error: Unbound value x


Maybe that having lone " between (* and *) should be forbidden? Or at least, it could emit a warning. I hopefully had camlp4 parsing and also had to see the temp file instead of the source directly, but without that, I would probably have spent some time on this issue.
(0006929)
glondu   
2012-02-16 09:20   
> Having an unterminated string in a comment is an ocaml error [...]

Is this documented somewhere? I would expect it in section 6.1 ("Lexical conventions", paragraph "Comments"), but couldn't find mention of this even by grepping through the whole manual.
(0007125)
xleroy   
2012-03-21 16:35   
I can't reproduce the crash with OCaml 4.00 dev. Closing this PR.

$ cat foo.ml
cat dupa.ml
(* Some " to be printed *)
let () = print_char '"'; print_newline ();;
$ ocamldoc foo.ml
File "foo.ml", line 2, characters 0-2:
Error: Comment not terminated
1 error(s) encountered