Skip to content

Commit

Permalink
[ioctl] Incorrect conversion between integer types (#3522)
Browse files Browse the repository at this point in the history
 Incorrect conversion between integer types
  • Loading branch information
huof6829 authored Jul 14, 2022
1 parent bfbaece commit ad61fa3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 7 additions & 5 deletions ioctl/cmd/bc/bcbucketlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,26 @@ func (m *bucketlistMessage) String() string {

// getBucketList get bucket list from chain
func getBucketList(method, addr string, args ...string) (err error) {
offset, limit := uint64(0), uint64(1000)
offset, limit := uint32(0), uint32(1000)
if len(args) > 0 {
offset, err = strconv.ParseUint(args[0], 10, 64)
val, err := strconv.ParseUint(args[0], 10, 32)
if err != nil {
return output.NewError(output.ValidationError, "invalid offset", err)
}
offset = uint32(val)
}
if len(args) > 1 {
limit, err = strconv.ParseUint(args[1], 10, 64)
val, err := strconv.ParseUint(args[1], 10, 32)
if err != nil {
return output.NewError(output.ValidationError, "invalid limit", err)
}
limit = uint32(val)
}
switch method {
case _bucketlistMethodByVoter:
return getBucketListByVoter(addr, uint32(offset), uint32(limit))
return getBucketListByVoter(addr, offset, limit)
case _bucketlistMethodByCandidate:
return getBucketListByCand(addr, uint32(offset), uint32(limit))
return getBucketListByCand(addr, offset, limit)
}
return output.NewError(output.InputError, "unknown <method>", nil)
}
Expand Down
17 changes: 10 additions & 7 deletions ioctl/newcmd/bc/bcbucketlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,40 @@ func NewBCBucketListCmd(client ioctl.Client) *cobra.Command {
err error
)

offset, limit := uint64(0), uint64(1000)
method, addr := args[0], args[1]
s := args[2:]
offset, limit := uint32(0), uint32(1000)
method, addr, s := args[0], args[1], args[2:]

if len(s) > 0 {
offset, err = strconv.ParseUint(s[0], 10, 64)
val, err := strconv.ParseUint(s[0], 10, 32)
if err != nil {
return errors.Wrap(err, "invalid offset")
}
offset = uint32(val)
}
if len(s) > 1 {
limit, err = strconv.ParseUint(s[1], 10, 64)
val, err := strconv.ParseUint(s[1], 10, 32)
if err != nil {
return errors.Wrap(err, "invalid limit")
}
limit = uint32(val)
}

switch method {
case MethodVoter:
address, err = client.AddressWithDefaultIfNotExist(addr)
if err != nil {
return err
}
bl, err = getBucketListByVoterAddress(client, address, uint32(offset), uint32(limit))
bl, err = getBucketListByVoterAddress(client, address, offset, limit)
case MethodCandidate:
bl, err = getBucketListByCandidateName(client, addr, uint32(offset), uint32(limit))
bl, err = getBucketListByCandidateName(client, addr, offset, limit)
default:
return errors.New("unknown <method>")
}
if err != nil {
return err
}

var lines []string
if len(bl.Buckets) == 0 {
lines = append(lines, "Empty bucketlist with given address")
Expand Down

0 comments on commit ad61fa3

Please sign in to comment.