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

Format.advance_left is not tail rec #4273

Closed
vicuna opened this issue Apr 30, 2007 · 4 comments
Closed

Format.advance_left is not tail rec #4273

vicuna opened this issue Apr 30, 2007 · 4 comments
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Apr 30, 2007

Original bug ID: 4273
Reporter: monate
Assigned to: @pierreweis
Status: closed (set by @pierreweis on 2008-09-08T12:35:31Z)
Resolution: fixed
Priority: normal
Severity: crash
Version: 3.09.3
Fixed in version: 3.10.0
Category: ~DO NOT USE (was: OCaml general)
Monitored by: pascal_cuoq monate ertai

Bug description

Dear 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
end
in
try
aux state
with Empty_queue -> ();;

@vicuna
Copy link
Author

vicuna commented May 8, 2007

Comment author: @pierreweis

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.

@vicuna
Copy link
Author

vicuna commented May 9, 2007

Comment author: monate

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.

@vicuna
Copy link
Author

vicuna commented Jun 16, 2008

Comment author: monate

The patch is still not present in 3.10.2 and the issue remains. The release process may have lost it.

@vicuna
Copy link
Author

vicuna commented Sep 8, 2008

Comment author: @pierreweis

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.

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

2 participants