From 50fa64677611313bdd343c1dab85bf0c297d21a4 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 10 Nov 2015 11:32:26 -0800 Subject: [PATCH] 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 --- src/cmd/compile/internal/gc/mparith3.go | 5 +++++ 1 file changed, 5 insertions(+) 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) -- 2.48.1