Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001324OCamlOCaml generalpublic2002-08-14 19:492002-08-19 10:53
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0001324: ocaml crash after use scanf.ml;; sscanf ...
DescriptionFull_Name: Nick Alexander
Version: 3.05
OS: Win2k, Mac OS X
Submission from: h209-139-221-124.gtconnect.net (209.139.221.124)


Hello,

If I try, in the ocamlwin toplevel under Win2k, something like:

Objective Caml version 3.05

# open Scanf;;
# let q = sscanf "10 11" "%d %d" (fun x y -> print_endline (x ^ y));;
Characters 58-59:
  let q = sscanf "10 11" "%d %d" (fun x y -> print_endline (x ^ y));;
                                                            ^
This expression has type int but is here used with type string
#

I get good type checking.

When I try:

        Objective Caml version 3.05

# #use "C:/Program Files/Objective Caml/lib/scanf.ml";;
module type SCANNING =

[ load elided ]

# let q = sscanf "10 11" "%d %d" (fun x y -> print_endline (x ^ y));;

I get a hard crash (segfault) with invalid memory access.

A friend verified this behaviour under Mac OS X.

Nick Alexander

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0002553)
administrator (administrator)
2002-08-15 12:17

> Full_Name: Nick Alexander
> Version: 3.05
> OS: Win2k, Mac OS X
> Submission from: h209-139-221-124.gtconnect.net (209.139.221.124)
>
>
> Hello,
>
> If I try, in the ocamlwin toplevel under Win2k, something like:
>
> Objective Caml version 3.05
>
> # open Scanf;;
> # let q = sscanf "10 11" "%d %d" (fun x y -> print_endline (x ^ y));;
> Characters 58-59:
> let q = sscanf "10 11" "%d %d" (fun x y -> print_endline (x ^ y));;
> ^
> This expression has type int but is here used with type string
> #
>
> I get good type checking.
>
> When I try:
>
> Objective Caml version 3.05
>
> # #use "C:/Program Files/Objective Caml/lib/scanf.ml";;
> module type SCANNING =
>
> [ load elided ]
>
> # let q = sscanf "10 11" "%d %d" (fun x y -> print_endline (x ^ y));;
>
> I get a hard crash (segfault) with invalid memory access.
>
> A friend verified this behaviour under Mac OS X.
>
> Nick Alexander

Thank you for your interest for Objective Caml and tahnk you for a
clean the bug report.

However, I'm afraid this is not a bug, but a misusage of the Scanf
module! In the following, I explain why the behaviour you observe is
normal.

First of all, remember that the Scanf module is ... a module! In other
words, the file scanf.ml is not the module, it is just the
implementation part of the Scanf module: the module is also equipped
with a companion file, its interface file, namely scanf.mli. It hapens
that the functions defined in scanf.ml are much too general (hence
your seg fault with a ill-typed phrase) and that their types have to
be restricted by the Scanf module interface. That's why the file
scanf.mli is mandatory to give the right typings for the functions
defined in scanf.ml.

Hence, you should not forget to use the interface of Scanf with the
implementation of Scanf, as in:

vignaud:~$ ocaml
        Objective Caml version 3.06

# #use "src/csl/stdlib/scanf.ml";;
module type SCANNING =
[...]
# open Scanf;;
# let q = sscanf "10 11" "%d %d" (fun x y -> print_endline (x ^ y));;
This expression has type int but is here used with type string
#

Admittedly, we can directly restrict the type of the functions
exported by Scanf from within the implementation. However, this would
not solve completely the problem, since loading directly the
implementation file of the Scanf module grants you access to low-level
functions that could break the invariants of the scanning functions
and cause them to crash; hence, even if we restrict types in scanf.ml,
you could still experience errors when loading directly the
implementation file and by-passing the interface file visibility
and typing restrictions.

In conclusion, don't #use random files from the Caml compiler
distribution! Those files may have invariants or typing restrictions
that you can violate by skipping the interface logical restrictions
that are supposed to be stuck to the implementation.

Best regards,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ [^]


(0002554)
administrator (administrator)
2002-08-19 10:53

scanf.ml is not designed to be #use -ed.

- Issue History
Date Modified Username Field Change
2005-11-18 10:14 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker