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

Unsound type checking of format strings for the Format module #6115

Closed
vicuna opened this issue Aug 2, 2013 · 1 comment
Closed

Unsound type checking of format strings for the Format module #6115

vicuna opened this issue Aug 2, 2013 · 1 comment
Assignees

Comments

@vicuna
Copy link

vicuna commented Aug 2, 2013

Original bug ID: 6115
Reporter: aguatto
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2015-12-11T18:21:25Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.00.1
Category: typing
Related to: #5380
Monitored by: @hcarty

Bug description

According to the Format documentation, when used in a format string
'@%' prints a '%' character. Thus, the following variable should be
of type 'unit' and print '%s' on the standard output. However, the
type checker thinks that %s is a format specifier:

let f = Format.printf "@%s";;

val f : string -> unit =

f "unused";;

%s- : unit = ()

This leads to segfault in more complex cases (see "Steps to reproduce").

Steps to reproduce

  1. Run the ocaml toplevel

  2. Enter the following code:

     OCaml version 4.00.1
    

Format.printf "@%s%a" "unused" (fun fmt x -> Format.fprintf fmt "%d" x) 42;;

  1. Witness segfault.
@vicuna
Copy link
Author

vicuna commented Aug 2, 2013

Comment author: @gasche

This has been fixed in the development version:

Format.printf "@%s%a" "unused" (fun fmt x -> Format.fprintf fmt "%d" x) 42;;

Exception:
Invalid_argument
"Format.fprintf: bad format '@%s%a', giving up at character number 1 (%).".

It's still the kind of issues that a well-typed approach, as in #6017, would rule out statically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants