Skip to content

Commit

Permalink
staticcheck/vrp: short-circuit widening in presence of too many const…
Browse files Browse the repository at this point in the history
…ants
  • Loading branch information
dominikh committed Apr 26, 2019
1 parent fa2767c commit 16ee8ce
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions staticcheck/vrp/vrp.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,16 +722,22 @@ func (g *Graph) widen(c Constraint, consts []Z) bool {
}
nlc := NInfinity
nuc := PInfinity
for _, co := range consts {
if co.Cmp(ni.Lower) <= 0 {
nlc = co
break

// Don't get stuck widening for an absurd amount of time due
// to an excess number of constants, as may be present in
// table-based scanners.
if len(consts) < 1000 {
for _, co := range consts {
if co.Cmp(ni.Lower) <= 0 {
nlc = co
break
}
}
}
for _, co := range consts {
if co.Cmp(ni.Upper) >= 0 {
nuc = co
break
for _, co := range consts {
if co.Cmp(ni.Upper) >= 0 {
nuc = co
break
}
}
}

Expand Down

0 comments on commit 16ee8ce

Please sign in to comment.