mirror of
https://github.com/divan/expvarmon.git
synced 2025-04-25 13:48:54 +08:00
fix panic occurs when using Float value
This commit is contained in:
parent
63bb111ee8
commit
b33870f09c
28
stack.go
28
stack.go
@ -35,12 +35,36 @@ func (s *Stack) Push(val VarValue) {
|
|||||||
|
|
||||||
switch val.(type) {
|
switch val.(type) {
|
||||||
case int64:
|
case int64:
|
||||||
if s.Max == nil || val.(int64) > s.Max.(int64) {
|
if s.Max == nil {
|
||||||
s.Max = val
|
s.Max = val
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch s.Max.(type) {
|
||||||
|
case int64:
|
||||||
|
if val.(int64) > s.Max.(int64) {
|
||||||
|
s.Max = val
|
||||||
|
}
|
||||||
|
case float64:
|
||||||
|
if float64(val.(int64)) > s.Max.(float64) {
|
||||||
|
s.Max = val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case float64:
|
case float64:
|
||||||
if s.Max == nil || val.(float64) > s.Max.(float64) {
|
if s.Max == nil {
|
||||||
s.Max = val
|
s.Max = val
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch s.Max.(type) {
|
||||||
|
case int64:
|
||||||
|
if val.(float64) > float64(s.Max.(int64)) {
|
||||||
|
s.Max = val
|
||||||
|
}
|
||||||
|
case float64:
|
||||||
|
if val.(float64) > s.Max.(float64) {
|
||||||
|
s.Max = val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,13 @@ package main
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
|
func TestPushWithFloatAndIntValue(t *testing.T) {
|
||||||
|
s := NewStack()
|
||||||
|
s.Push(VarValue(int64(0.0))) // from service.go:guessValue
|
||||||
|
s.Push(VarValue(5.0))
|
||||||
|
s.Push(VarValue(float64(15.0)))
|
||||||
|
}
|
||||||
|
|
||||||
func TestStack(t *testing.T) {
|
func TestStack(t *testing.T) {
|
||||||
size := 10
|
size := 10
|
||||||
s := NewStackWithSize(size)
|
s := NewStackWithSize(size)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user