Skip to content

Commit a5e2979

Browse files
committed
fix: enforce int64 for large integer values in tests
- Updated test cases in `goyaml.v2` and `goyaml.v3` `decode_test.go` to explicitly use `int64` for representing large integer values. - Adjusted `yaml_test.go` to: - Use `int64` for `math.MaxInt64` in marshaling tests. - Decode integers greater than `2^53` into `int64` instead of `int` to ensure proper handling of large values. These changes address potential issues with integer overflow and ensure compatibility across platforms with differing integer size representations. Signed-off-by: Arthur Diniz <[email protected]>
1 parent 119290a commit a5e2979

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

goyaml.v2/decode_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ var unmarshalTests = []struct {
131131
map[string]interface{}{"bin": -42},
132132
}, {
133133
"bin: -0b1000000000000000000000000000000000000000000000000000000000000000",
134-
map[string]interface{}{"bin": -9223372036854775808},
134+
map[string]interface{}{"bin": int64(-9223372036854775808)},
135135
}, {
136136
"decimal: +685_230",
137137
map[string]int{"decimal": 685230},

goyaml.v3/decode_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ var unmarshalTests = []struct {
177177
map[string]interface{}{"bin": -42},
178178
}, {
179179
"bin: -0b1000000000000000000000000000000000000000000000000000000000000000",
180-
map[string]interface{}{"bin": -9223372036854775808},
180+
map[string]interface{}{"bin": int64(-9223372036854775808)},
181181
}, {
182182
"decimal: +685_230",
183183
map[string]int{"decimal": 685230},

yaml_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ type MarshalTest struct {
183183
func TestMarshal(t *testing.T) {
184184
f32String := strconv.FormatFloat(math.MaxFloat32, 'g', -1, 32)
185185
s := MarshalTest{"a", math.MaxInt64, math.MaxFloat32}
186-
e := []byte(fmt.Sprintf("A: a\nB: %d\nC: %s\n", math.MaxInt64, f32String))
186+
e := []byte(fmt.Sprintf("A: a\nB: %d\nC: %s\n", int64(math.MaxInt64), f32String))
187187

188188
y, err := Marshal(s)
189189
if err != nil {
@@ -411,8 +411,8 @@ func TestUnmarshal(t *testing.T) {
411411
// decoding integers
412412
"decode 2^53 + 1 into int": {
413413
encoded: []byte("9007199254740993"),
414-
decodeInto: new(int),
415-
decoded: 9007199254740993,
414+
decodeInto: new(int64),
415+
decoded: int64(9007199254740993),
416416
},
417417
"decode 2^53 + 1 into interface": {
418418
encoded: []byte("9007199254740993"),

0 commit comments

Comments
 (0)