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

cmd/gc: converting len(slice) value to non-fitting numeric types should result in overflow error #33643

Open
nrvnrvn opened this issue Aug 14, 2019 · 4 comments

Comments

@nrvnrvn
Copy link

commented Aug 14, 2019

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

$ go version
go version go1.12.7

Does this issue reproduce with the latest release?

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

go env Output
$ go env
CC="clang"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_ENABLED="1"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
CXX="clang++"
GCCGO="gccgo"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lol/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/fq/v153jfj15jz73k94n8mzycl40000gn/T/go-build186400384=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOMOD="/mycoolproject/go.mod"
GOOS="darwin"
GOPATH="/Users/lol/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
PKG_CONFIG="pkg-config"

What did you do?

https://play.golang.org/p/4RP50Tv00i8

What did you expect to see?

https://play.golang.org/p/cvwZ7P8Fa_q

What did you see instead?

overflowing value is converted to 0

@zephyrtronium

This comment has been minimized.

Copy link

commented Aug 14, 2019

This is closely related to #30613 and the various issues linked therefrom. That discussion might benefit from your use case for a checked uint8 type.

@andybons andybons changed the title converting len(slice) value to non-fitting numeric types should result in overflow error cmd/gc: converting len(slice) value to non-fitting numeric types should result in overflow error Aug 15, 2019

@andybons

This comment has been minimized.

Copy link
Member

commented Aug 15, 2019

@nrvnrvn are you expecting an error at compile time or runtime?

@nrvnrvn

This comment has been minimized.

Copy link
Author

commented Aug 15, 2019

Good question. I would expect a runtime error.

@andybons

This comment has been minimized.

Copy link
Member

commented Aug 15, 2019

At first this seems like a dupe of #31500. Would you agree?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.