Skip to content

Commit

Permalink
Fix large literals type inference on 32 bits
Browse files Browse the repository at this point in the history
Some tests are failing because some large literal integers are meant to
be stored on 64 bits, but are stored on 32 on 32 bits architectures.
This causes the value to overflow.

This commit fixes this issue by using explicit int64 typing.

Signed-off-by: Julien Rische <jrische@redhat.com>
  • Loading branch information
jrisc committed Apr 29, 2022
1 parent e4f32a2 commit b4fe0c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions decode_test.go
Expand Up @@ -27,6 +27,9 @@ type Child struct {
}

func TestDecoder(t *testing.T) {
var in9223372036854775808 int64 = -9223372036854775808
var u4294967296 uint64 = 4294967296
var i4294967296 int64 = 4294967296
tests := []struct {
source string
value interface{}
Expand Down Expand Up @@ -89,7 +92,7 @@ func TestDecoder(t *testing.T) {
},
{
"v: -0b1000000000000000000000000000000000000000000000000000000000000000",
map[string]interface{}{"v": -9223372036854775808},
map[string]interface{}{"v": in9223372036854775808},
},
{
"v: 0xA",
Expand All @@ -109,7 +112,7 @@ func TestDecoder(t *testing.T) {
},
{
"v: 4294967296\n",
map[string]int{"v": 4294967296},
map[string]int64{"v": i4294967296},
},
{
"v: 0.1\n",
Expand Down Expand Up @@ -200,7 +203,7 @@ func TestDecoder(t *testing.T) {
map[string]uint{"v": 42},
}, {
"v: 4294967296",
map[string]uint64{"v": 4294967296},
map[string]uint64{"v": u4294967296},
},

// int
Expand Down
3 changes: 2 additions & 1 deletion encode_test.go
Expand Up @@ -18,6 +18,7 @@ var zero = 0
var emptyStr = ""

func TestEncoder(t *testing.T) {
var i4294967296 int64 = 4294967296
tests := []struct {
source string
value interface{}
Expand Down Expand Up @@ -65,7 +66,7 @@ func TestEncoder(t *testing.T) {
},
{
"v: 4294967296\n",
map[string]int{"v": 4294967296},
map[string]int64{"v": i4294967296},
nil,
},
{
Expand Down

0 comments on commit b4fe0c2

Please sign in to comment.