Skip to content

Commit

Permalink
cmd/compile/internal/gc: avoid potential endless loop in float printing
Browse files Browse the repository at this point in the history
The compiler should not usually call Fconv with an infinity, but if
it does, Fconv will end in an endless loop. Test for infinities early.

Change-Id: I48f366466538b0bd26a851e01258725025babaff
Reviewed-on: https://go-review.googlesource.com/16777
Reviewed-by: Russ Cox <rsc@golang.org>
  • Loading branch information
griesemer committed Nov 10, 2015
1 parent 2fdff95 commit 50fa646
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cmd/compile/internal/gc/mparith3.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ func Fconv(fvp *Mpflt, flag int) string {
sign = "+"
}

// Don't try to convert infinities (will not terminate).
if f.IsInf() {
return sign + "Inf"
}

// Use fmt formatting if in float64 range (common case).
if x, _ := f.Float64(); !math.IsInf(x, 0) {
return fmt.Sprintf("%s%.6g", sign, x)
Expand Down

0 comments on commit 50fa646

Please sign in to comment.