Fix string to int64 conversion for SNMP input (#7407)

This commit is contained in:
Mark Drayton 2020-04-24 22:35:59 +02:00 committed by GitHub
parent 8957032790
commit 1bb436e8a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -804,9 +804,9 @@ func fieldConvert(conv string, v interface{}) (interface{}, error) {
case uint64: case uint64:
v = int64(vt) v = int64(vt)
case []byte: case []byte:
v, _ = strconv.Atoi(string(vt)) v, _ = strconv.ParseInt(string(vt), 10, 64)
case string: case string:
v, _ = strconv.Atoi(vt) v, _ = strconv.ParseInt(vt, 10, 64)
} }
return v, nil return v, nil
} }

View File

@ -694,6 +694,8 @@ func TestFieldConvert(t *testing.T) {
{uint64(123), "float(3)", float64(0.123)}, {uint64(123), "float(3)", float64(0.123)},
{"123", "int", int64(123)}, {"123", "int", int64(123)},
{[]byte("123"), "int", int64(123)}, {[]byte("123"), "int", int64(123)},
{"123123123123", "int", int64(123123123123)},
{[]byte("123123123123"), "int", int64(123123123123)},
{float32(12.3), "int", int64(12)}, {float32(12.3), "int", int64(12)},
{float64(12.3), "int", int64(12)}, {float64(12.3), "int", int64(12)},
{int(123), "int", int64(123)}, {int(123), "int", int64(123)},