Skip to content
Snippets Groups Projects

Fix potential stack overflow related to `Pretty N`.

Merged Robbert Krebbers requested to merge robbert/pretty_N_go_stackoverflow into master
All threads resolved!
2 files
+ 13
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 4
1
@@ -22,8 +22,11 @@ Fixpoint pretty_N_go_help (x : N) (acc : Acc (<)%N x) (s : string) : string :=
(String (pretty_N_char (x `mod` 10)) s)
| right _ => s
end.
(** The argument [S (N.size_nat x)] of [wf_guard] makes sure that computation
works if [x] is a closed term, but that it blocks if [x] is an open term. The
latter prevents unexpected stack overflows, see [tests/pretty.v]. *)
Definition pretty_N_go (x : N) : string string :=
pretty_N_go_help x (wf_guard 32 N.lt_wf_0 x).
pretty_N_go_help x (wf_guard (S (N.size_nat x)) N.lt_wf_0 x).
Global Instance pretty_N : Pretty N := λ x,
if decide (x = 0)%N then "0" else pretty_N_go x "".
Loading