Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ioctl] Incorrect conversion between integer types #3522

Merged
merged 11 commits into from
Jul 14, 2022
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