Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stdpp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adam
stdpp
Commits
6de30407
Commit
6de30407
authored
3 years ago
by
Robbert Krebbers
Browse files
Options
Downloads
Patches
Plain Diff
Fix potential stack overflow related to `Pretty N`.
parent
0a38be45
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/pretty.v
+12
-0
12 additions, 0 deletions
tests/pretty.v
theories/pretty.v
+1
-1
1 addition, 1 deletion
theories/pretty.v
with
13 additions
and
1 deletion
tests/pretty.v
+
12
−
0
View file @
6de30407
From
stdpp
Require
Import
pretty
.
From
Coq
Require
Import
Ascii
.
Section
N
.
Local
Open
Scope
N_scope
.
...
...
@@ -17,6 +18,17 @@ Section N.
Proof
.
reflexivity
.
Qed
.
End
N
.
(** Minimized version of:
https://coq.zulipchat.com/#narrow/stream/237977-Coq-users/topic/Stack.20overflow.20in.20Qed.2E
Fixed by making the [wp_guard] in [pretty_N_go] proportional to the
size of the input so that it blocks in case the input is an open term. *)
Lemma
test_no_stack_overflow
p
n
:
get
n
(
pretty
(
N
.
pos
p
))
≠
Some
"_"
%
char
→
get
(
S
n
)
(
"-"
+:+
pretty
(
N
.
pos
p
))
≠
Some
"_"
%
char
.
Proof
.
intros
Hlem
.
apply
Hlem
.
Qed
.
Section
nat
.
Local
Open
Scope
nat_scope
.
...
...
This diff is collapsed.
Click to expand it.
theories/pretty.v
+
1
−
1
View file @
6de30407
...
...
@@ -23,7 +23,7 @@ Fixpoint pretty_N_go_help (x : N) (acc : Acc (<)%N x) (s : string) : string :=
|
right
_
=>
s
end
.
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
""
.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment