Giter Club home page Giter Club logo

Comments (4)

juniuszhou avatar juniuszhou commented on September 14, 2024

According to the go doc, Atoi is equivalent to ParseInt(s, 10, 0). I don't see there is necessity to use ParseInt. We can close it after one more agreement from @Brando753 @smartyalgo @banshee

from sifnode.

smartyalgo avatar smartyalgo commented on September 14, 2024

So the issue is:
AtoI outputs int32/int64 depending on the machine.
This could be an issue if downstream expects int32, and we're passing int64
e.g.
In cli/tx.go

func GetCmdUpdateWhiteListValidator() *cobra.Command {
...
188 power , err := strconv . Atoi ( args [2])

power is type int, aka int64 depending on the machine. Later on, it is cast as uint32 to updateWhiteListValidator, thus downcasting.
if caller tries to update validator power to 4294967296 (max uint32 + 1), the uint32 cast results in 0

ParseInt returns an err, which will tell us when string input is out of range, thus preventing input beyond int32 range

	var power64string string = "9223372036854775807"

	power32, err := strconv.ParseInt(power64string, 10, 32)
	if err != nil {
		fmt.Println("Errored", err)
	}
	fmt.Println(power32)

Gives

Errored strconv.ParseInt: parsing "9223372036854775807": value out of range
2147483647

from sifnode.

juniuszhou avatar juniuszhou commented on September 14, 2024

I agree, ParseInt can avoid this downcasting error. will create a PR to fix it.

from sifnode.

juniuszhou avatar juniuszhou commented on September 14, 2024

close it after #3287 merged.

from sifnode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.