Skip to content

math/big: SetString does not handle malformed input correctly  #17001

@Tom-Coates

Description

@Tom-Coates

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.5 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tomc/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.5/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.5/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT=""
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

Using SetString to convert "4/3/2" to a *big.Rat claimed to succeed (which I think is the wrong behaviour) and returned 4/3 as the result (which is definitely the wrong behaviour)

https://play.golang.org/p/6iUww8dSlJ

What did you expect to see?

I expected the boolean ok in

_, ok := x.SetString("4/3/2")

to be false.

What did you see instead?

ok was true, and x was set to the rational number 4/3.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions