Skip to content

Commit

Permalink
Fix edge case when decoding MinInt as -0b.
Browse files Browse the repository at this point in the history
Closes #87.
  • Loading branch information
niemeyer committed Mar 26, 2018
1 parent 62e345d commit 7b8fd2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ var unmarshalTests = []struct {
}, {
"bin: -0b101010",
map[string]interface{}{"bin": -42},
}, {
"bin: -0b1000000000000000000000000000000000000000000000000000000000000000",
map[string]interface{}{"bin": -9223372036854775808},
}, {
"decimal: +685_230",
map[string]int{"decimal": 685230},
Expand Down
8 changes: 4 additions & 4 deletions resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ func resolve(tag string, in string) (rtag string, out interface{}) {
return yaml_INT_TAG, uintv
}
} else if strings.HasPrefix(plain, "-0b") {
intv, err := strconv.ParseInt(plain[3:], 2, 64)
intv, err := strconv.ParseInt("-" + plain[3:], 2, 64)
if err == nil {
if intv == int64(int(intv)) {
return yaml_INT_TAG, -int(intv)
if true || intv == int64(int(intv)) {
return yaml_INT_TAG, int(intv)
} else {
return yaml_INT_TAG, -intv
return yaml_INT_TAG, intv
}
}
}
Expand Down

0 comments on commit 7b8fd2d

Please sign in to comment.