mirror of
https://github.com/golang/go
synced 2024-11-18 03:04:45 -07: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:
parent
2fdff9586b
commit
50fa646776
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user