1
0
mirror of https://github.com/golang/go synced 2024-09-30 06:24:33 -06:00

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 <rsc@golang.org>
This commit is contained in:
Robert Griesemer 2015-11-10 11:32:26 -08:00
parent 2fdff9586b
commit 50fa646776

View File

@ -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)