Fix int overflow by int -> uint32 and uint64 conversion

pull/1802/head
flicker-harmony 5 years ago
parent 56d8be1562
commit e410b13c70
  1. 4
      internal/hmyapi/transactionpool.go
  2. 6
      internal/hmyapi/util.go

@ -24,8 +24,8 @@ var (
// TxHistoryArgs is struct to make GetTransactionsHistory request
type TxHistoryArgs struct {
Address string `json:"address"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
PageIndex uint32 `json:"pageIndex"`
PageSize uint32 `json:"pageSize"`
FullTx bool `json:"fullTx"`
TxType string `json:"txType"`
Order string `json:"order"`

@ -13,7 +13,7 @@ import (
// defaultPageSize is to have default pagination.
const (
defaultPageSize = 100
defaultPageSize = uint32(100)
)
// ReturnWithPagination returns result with pagination (offset, page in TxHistoryArgs).
@ -23,10 +23,10 @@ func ReturnWithPagination(hashes []common.Hash, args TxHistoryArgs) []common.Has
if args.PageSize > 0 {
pageSize = args.PageSize
}
if pageIndex < 0 || pageSize*pageIndex >= len(hashes) {
if uint64(pageSize)*uint64(pageIndex) >= uint64(len(hashes)) {
return make([]common.Hash, 0)
}
if pageSize*pageIndex+pageSize > len(hashes) {
if uint64(pageSize)*uint64(pageIndex)+uint64(pageSize) > uint64(len(hashes)) {
return hashes[pageSize*pageIndex:]
}
return hashes[pageSize*pageIndex : pageSize*pageIndex+pageSize]

Loading…
Cancel
Save