From: Robert Griesemer Date: Tue, 10 Nov 2015 19:32:26 +0000 (-0800) Subject: cmd/compile/internal/gc: avoid potential endless loop in float printing X-Git-Tag: go1.6beta1~568 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=50fa64677611313bdd343c1dab85bf0c297d21a4;p=gostls13.git cmd/compile/internal/gc: avoid potential endless loop in float printing 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 --- diff --git a/src/cmd/compile/internal/gc/mparith3.go b/src/cmd/compile/internal/gc/mparith3.go index 4aa283fe33..889c461cc9 100644 --- a/src/cmd/compile/internal/gc/mparith3.go +++ b/src/cmd/compile/internal/gc/mparith3.go @@ -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)