Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006115OCamltypingpublic2013-08-02 14:272015-12-11 19:21
Assigned Togasche 
PlatformOSOS Version
Product Version4.00.1 
Target VersionFixed in Version 
Summary0006115: Unsound type checking of format strings for the Format module
DescriptionAccording 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 = <fun>
# f "unused";;
%s- : unit = ()

This leads to segfault in more complex cases (see "Steps to reproduce").
Steps To Reproduce1. 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;;
3. Witness segfault.
TagsNo tags attached.
Attached Files

- Relationships
related to 0005380closedweis Strange sscanf input segfault 

-  Notes
gasche (developer)
2013-08-02 19:25

This has been fixed in the development version:

# Format.printf "@%s%a" "unused" (fun fmt x -> Format.fprintf fmt "%d" x) 42;;
 "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 PR#6017, would rule out statically.

- Issue History
Date Modified Username Field Change
2013-08-02 14:27 aguatto New Issue
2013-08-02 19:25 gasche Note Added: 0010083
2013-08-02 19:25 gasche Status new => resolved
2013-08-02 19:25 gasche Resolution open => fixed
2013-08-02 19:25 gasche Assigned To => gasche
2013-08-02 22:18 gasche Relationship added related to 0005380
2015-12-11 19:21 xleroy Status resolved => closed
2017-02-23 16:45 doligez Category OCaml typing => typing

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker