Skip to content

Commit

Permalink
fixup! feat: introduce UIntNode interface, used within DAG-CBOR codec
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jun 8, 2022
1 parent adcc36d commit e1c3911
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions codec/dagcbor/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ func TestInts(t *testing.T) {
qt.Assert(t, ii, qt.Equals, int64(td.intValue))
}

// if it's a positive number, we should be able to access it as a UintNode
// and be able to access the full int64 range
// if the number is outside of the positive int64 range, we should be able
// to access it as a UintNode and be able to access the full int64 range
uin, ok := n.(datamodel.UintNode)
if td.intValue < 0 {
if td.value <= math.MaxInt64 {
qt.Assert(t, ok, qt.IsFalse)
} else {
qt.Assert(t, ok, qt.IsTrue)
Expand Down
7 changes: 6 additions & 1 deletion codec/dagcbor/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,12 @@ func unmarshal2(na datamodel.NodeAssembler, tokSrc shared.TokenSource, tk *tok.T
if *gas < 0 {
return ErrAllocationBudgetExceeded
}
return na.AssignNode(basicnode.NewUint(tk.Uint))
// note that this pushes any overflow errors up the stack when AsInt() may
// be called on a UintNode that is too large to cast to an int64
if tk.Uint > math.MaxInt64 {
return na.AssignNode(basicnode.NewUint(tk.Uint))
}
return na.AssignInt(int64(tk.Uint))
case tok.TFloat64:
*gas -= 1
if *gas < 0 {
Expand Down

0 comments on commit e1c3911

Please sign in to comment.