]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: avoid potential endless loop in float printing
authorRobert Griesemer <gri@golang.org>
Tue, 10 Nov 2015 19:32:26 +0000 (11:32 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 10 Nov 2015 20:36:52 +0000 (20:36 +0000)
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>
src/cmd/compile/internal/gc/mparith3.go

index 4aa283fe33aa2c806c056e6f78565e963e29d16e..889c461cc9e44114ed8a8893aaeb9809997de195 100644 (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)