Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004273OCamlOCaml generalpublic2007-04-30 16:452008-09-08 14:35
Assigned Toweis 
PlatformOSOS Version
Product Version3.09.3 
Target VersionFixed in Version3.10.0 
Summary0004273: Format.advance_left is not tail rec
DescriptionDear Caml'ers,

Calling Format.advance_left may raise Stack_overflow because it is not tail rec.
Here is a tentative fix :

let advance_left state =
 let rec aux state =
    match peek_queue state.pp_queue with
     {elem_size = size; token = tok; length = len} ->
      let size = int_of_size size in
      if not
       (size < 0 &&
        (state.pp_right_total - state.pp_left_total < state.pp_space_left))
       then begin
        ignore(take_queue state.pp_queue);
        format_pp_token state (if size < 0 then pp_infinity else size) tok;
        state.pp_left_total <- len + state.pp_left_total;
        aux state
   aux state
   with Empty_queue -> ();;
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
weis (developer)
2007-05-08 23:38

Have you indeed encountered such a stack overflow due to advance_left ?

If so, could you please send me the example ?

When I wrote advance_left, I was convinced that this could not happen :(
That's why I'm really interested at reading a counterexample!

Anyway, I already changed the code to get advance_left tailrec, since this could not hurt efficiency.
monate (reporter)
2007-05-09 10:11

Yes I did encounter this stack overflow.
Sadly, I cannot give you the example but here is a rough description.

The code causing the stack overflow is a pretty printer for memory states of an analyzer of one very large C code.
It uses a lot of nested %a and stack overflows after 12000 lines of output.
Doubling the stack size fixes the problem.
The patch prevents the stack overflow without changing the stack size.

Thanks again.
monate (reporter)
2008-06-16 11:05

The patch is still not present in 3.10.2 and the issue remains. The release process may have lost it.
weis (developer)
2008-09-08 14:33

You were right: the fix was lost in the release process, or I forgot to report it in the relevant branch.

This must be definitely fixed now :)

Thanks for your feed back.

- Issue History
Date Modified Username Field Change
2007-04-30 16:45 monate New Issue
2007-05-08 23:38 weis Note Added: 0004041
2007-05-08 23:39 weis Status new => assigned
2007-05-08 23:39 weis Assigned To => weis
2007-05-09 10:11 monate Note Added: 0004042
2007-05-25 09:41 weis Status assigned => closed
2007-05-25 09:41 weis Resolution open => fixed
2007-05-25 09:41 weis Fixed in Version => 3.10.0
2008-06-16 11:05 monate Status closed => feedback
2008-06-16 11:05 monate Resolution fixed => reopened
2008-06-16 11:05 monate Note Added: 0004522
2008-09-08 14:33 weis Note Added: 0004601
2008-09-08 14:35 weis Status feedback => closed
2008-09-08 14:35 weis Resolution reopened => fixed

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker