Commit 50fa6467 authored by Robert Griesemer's avatar Robert Griesemer

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/16777Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 2fdff958
...@@ -207,6 +207,11 @@ func Fconv(fvp *Mpflt, flag int) string { ...@@ -207,6 +207,11 @@ func Fconv(fvp *Mpflt, flag int) string {
sign = "+" 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). // Use fmt formatting if in float64 range (common case).
if x, _ := f.Float64(); !math.IsInf(x, 0) { if x, _ := f.Float64(); !math.IsInf(x, 0) {
return fmt.Sprintf("%s%.6g", sign, x) return fmt.Sprintf("%s%.6g", sign, x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment