Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocaml crash after use scanf.ml;; sscanf ... #3529

Closed
vicuna opened this issue Aug 14, 2002 · 2 comments
Closed

ocaml crash after use scanf.ml;; sscanf ... #3529

vicuna opened this issue Aug 14, 2002 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 14, 2002

Original bug ID: 1324
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

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

@vicuna
Copy link
Author

vicuna commented Aug 15, 2002

Comment author: administrator

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/

@vicuna
Copy link
Author

vicuna commented Aug 19, 2002

Comment author: administrator

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

@vicuna vicuna closed this as completed Aug 19, 2002
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant