diff --git a/bitswap/benchmarks_test.go b/bitswap/benchmarks_test.go index 53e75972b..e2085f661 100644 --- a/bitswap/benchmarks_test.go +++ b/bitswap/benchmarks_test.go @@ -598,10 +598,7 @@ func unixfsFileFetchLarge(b *testing.B, bs *bitswap.Bitswap, ks []cid.Cid) { for len(rest) > 0 { var batch [][]cid.Cid for i := 0; i < 5 && len(rest) > 0; i++ { - cnt := 10 - if len(rest) < 10 { - cnt = len(rest) - } + cnt := min(len(rest), 10) group := rest[:cnt] rest = rest[cnt:] batch = append(batch, group) diff --git a/gateway/backend_blocks.go b/gateway/backend_blocks.go index 656d158e5..f5927c2af 100644 --- a/gateway/backend_blocks.go +++ b/gateway/backend_blocks.go @@ -503,10 +503,7 @@ func walkGatewaySimpleSelector(ctx context.Context, lastCid cid.Cid, terminalBlk if err != nil { return err } - from = fileLength + entityRange.From - if from < 0 { - from = 0 - } + from = max(fileLength+entityRange.From, 0) foundFileLength = true } diff --git a/ipld/merkledag/coding.go b/ipld/merkledag/coding.go index fb7d18c3d..4195a8e0e 100644 --- a/ipld/merkledag/coding.go +++ b/ipld/merkledag/coding.go @@ -81,10 +81,8 @@ func (n *ProtoNode) marshalImmutable() (*immutableProtoNode, error) { qp.ListEntry(la, qp.Map(3, func(ma ipld.MapAssembler) { qp.MapEntry(ma, "Hash", qp.Link(cidlink.Link{Cid: link.Cid})) qp.MapEntry(ma, "Name", qp.String(link.Name)) - sz := int64(link.Size) - if sz < 0 { // overflow, >MaxInt64 is almost certainly an error - sz = 0 - } + // overflow, >MaxInt64 is almost certainly an error + sz := max(int64(link.Size), 0) qp.MapEntry(ma, "Tsize", qp.Int(sz)) })) }