Debian Codegraph @

debian/patches/0001-Fix-0b-on-32-bit-systems.patch

raw
1 Subject: Fix -0b on 32-bit systems
2 Bug: https://github.com/go-yaml/yaml/issues/441
3 Bug-Debian: https://bugs.debian.org/1040423
4 Origin: upstream, https://github.com/go-yaml/yaml/pull/442
5 From: Robert McQueen <[email protected]>
6
7 Date: Mon, 11 Mar 2019 12:51:26 +0000
8
9 7b8fd2d introduced a regression on 32-bit systems where -0b values would be
10 cast to an Int before being returned as a Int64, meaning that on 32-bit
11 systems, any negative value smaller than MinInt32 would get wrapped around and
12 returned incorrectly, causing the int64_neg_base2 decode_test to fail.
13
14 The test case also causes the bin test to fail on 32-bit systems because it
15 presumes the 64-bit edge case value can fit within an Int, which is not the
16 case on a 32-bit system.
17
18 Move the newly-introduced test case to the Int64-specific test cases, and
19 remove the undesirable coersion of Int64 values to Int when they do not fit.
20 ---
21 decode_test.go | 7 ++++---
22 resolve.go | 2 +-
23 2 files changed, 5 insertions(+), 4 deletions(-)
24
25 diff --git a/decode_test.go b/decode_test.go
26 index c7d104e..8e89179 100644
27 --- a/decode_test.go
28 +++ b/decode_test.go
29 @@ -129,9 +129,6 @@ var unmarshalTests = []struct {
30 }, {
31 "bin: -0b101010",
32 map[string]interface{}{"bin": -42},
33 - }, {
34 - "bin: -0b1000000000000000000000000000000000000000000000000000000000000000",
35 - map[string]interface{}{"bin": -9223372036854775808},
36 }, {
37 "decimal: +685_230",
38 map[string]int{"decimal": 685230},
39 @@ -302,6 +299,10 @@ var unmarshalTests = []struct {
40 "int64_min: -9223372036854775808",
41 map[string]int64{"int64_min": math.MinInt64},
42 },
43 + {
44 + "int64_min_base2: -0b1000000000000000000000000000000000000000000000000000000000000000",
45 + map[string]int64{"int64_min_base2": math.MinInt64},
46 + },
47 {
48 "int64_neg_base2: -0b111111111111111111111111111111111111111111111111111111111111111",
49 map[string]int64{"int64_neg_base2": -math.MaxInt64},
50 diff --git a/resolve.go b/resolve.go
51 index 4120e0c..5759580 100644
52 --- a/resolve.go
53 +++ b/resolve.go
54 @@ -182,7 +182,7 @@ func resolve(tag string, in string) (rtag string, out interface{}) {
55 } else if strings.HasPrefix(plain, "-0b") {
56 intv, err := strconv.ParseInt("-" + plain[3:], 2, 64)
57 if err == nil {
58 - if true || intv == int64(int(intv)) {
59 + if intv == int64(int(intv)) {
60 return yaml_INT_TAG, int(intv)
61 } else {
62 return yaml_INT_TAG, intv