From: Arthur Diniz Date: Fri, 10 Oct 2025 19:33:01 +0100 Subject: [PATCH] Fix int64 value handling in tests for cross-architecture compatibility (#120) Update test cases with overflow errors on 32-bit (i386) architectures. Signed-off-by: Arthur Diniz Origin: upstream, https://github.com/kubernetes-sigs/yaml/commit/537896d426f9ffce54c93ffb8196b4425d5275be Bug: https://github.com/kubernetes-sigs/yaml/pull/120 Applied-Upstream: 537896d426f9ffce54c93ffb8196b4425d5275be, not yet in a tagged release (post-v1.6.0) Last-Update: 2026-09-10 --- yaml_test.go | 33 ++++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/yaml_test.go b/yaml_test.go --- a/yaml_test.go +++ b/yaml_test.go @@ -37,6 +37,26 @@ return &str } +// newIntPtr returns a pointer to a new int or int64 based on architecture. +// On 64-bit platforms, it returns *int to test unsized int behavior. +// On 32-bit platforms, it returns *int64 to test the large value that doesn't fit in 32-bit int. +func newIntPtr() interface{} { + if strconv.IntSize == 64 { + return new(int) + } + return new(int64) +} + +// expectedIntValue returns the expected decoded value for architecture-specific int tests. +// On 64-bit platforms, it returns the value as int. +// On 32-bit platforms, it returns the value as int64 since the large value doesn't fit in 32-bit int. +func expectedIntValue(value int64) interface{} { + if strconv.IntSize == 64 { + return int(value) + } + return value +} + type errorType int const ( @@ -183,7 +203,7 @@ func TestMarshal(t *testing.T) { f32String := strconv.FormatFloat(math.MaxFloat32, 'g', -1, 32) s := MarshalTest{"a", math.MaxInt64, math.MaxFloat32} - e := []byte(fmt.Sprintf("A: a\nB: %d\nC: %s\n", math.MaxInt64, f32String)) + e := []byte(fmt.Sprintf("A: a\nB: %d\nC: %s\n", int64(math.MaxInt64), f32String)) y, err := Marshal(s) if err != nil { @@ -409,10 +429,15 @@ }, // decoding integers - "decode 2^53 + 1 into int": { + "decode 2^53 + 1 into int64": { + encoded: []byte("9007199254740993"), + decodeInto: new(int64), + decoded: int64(9007199254740993), + }, + "decode 2^53 + 1 into int (architecture-specific)": { encoded: []byte("9007199254740993"), - decodeInto: new(int), - decoded: 9007199254740993, + decodeInto: newIntPtr(), + decoded: expectedIntValue(9007199254740993), }, "decode 2^53 + 1 into interface": { encoded: []byte("9007199254740993"),