Skip to content

runtime: panic when accessing an empty struct value appended to an uninitialised slice #10135

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

Closed
0branch opened this issue Mar 11, 2015 · 3 comments

Comments

@0branch
Copy link

0branch commented Mar 11, 2015

I ran into the following runtime error while attempting access an empty struct value that had been appended to an uninitialised slice: https://play.golang.org/p/J2ItiISh2f,

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0xffffffff addr=0x0 pc=0x202e2]

The append (line 11) succeeds, as does printing the slice as a whole (line 12); accessing the appended struct via range (line 16) yields a panic. Issue encountered under 1.4.1; unable to replicate under gccgo.

Known workaround: comment out line 8 in favour of 9 and make an empty slice explicitly (yuck).


The following also work as expected, though they alter intended behaviour:

  • Modifying the struct to include a single field, allowing for default initialisation
  • Taking a slice of pointers []*empty
@minux minux added this to the Go1.5 milestone Mar 11, 2015
@minux minux changed the title Panic when accessing an empty struct value appended to an uninitialised slice runtime: panic when accessing an empty struct value appended to an uninitialised slice Mar 11, 2015
@minux
Copy link
Member

minux commented Mar 11, 2015

the problem is that append returns a slice with ptr=nil.
reproducible on tip.

@minux
Copy link
Member

minux commented Mar 11, 2015

I've sent https://golang.org/cl/7400

@minux minux self-assigned this Mar 11, 2015
@ianlancetaylor ianlancetaylor modified the milestones: Go1.4.3, Go1.5 Mar 11, 2015
@minux minux closed this as completed in 0d6a0d6 Mar 12, 2015
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/14248 mentions this issue.

minux added a commit that referenced this issue Sep 22, 2015
… non-zero len from growslice

Fixes #10135.

Change-Id: Ic4c5ab15bcb7b9c3fcc685a788d3b59c60c26e1e
Signed-off-by: Shenghou Ma <[email protected]>
Reviewed-on: https://go-review.googlesource.com/7400
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-on: https://go-review.googlesource.com/14248
Reviewed-by: Andrew Gerrand <[email protected]>
@ianlancetaylor ianlancetaylor modified the milestone: Go1.4.3 Sep 22, 2015
@golang golang locked and limited conversation to collaborators Sep 22, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
… non-zero len from growslice

Fixes golang#10135.

Change-Id: Ic4c5ab15bcb7b9c3fcc685a788d3b59c60c26e1e
Signed-off-by: Shenghou Ma <[email protected]>
Reviewed-on: https://go-review.googlesource.com/7400
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-on: https://go-review.googlesource.com/14248
Reviewed-by: Andrew Gerrand <[email protected]>
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
… non-zero len from growslice

Fixes golang#10135.

Change-Id: Ic4c5ab15bcb7b9c3fcc685a788d3b59c60c26e1e
Signed-off-by: Shenghou Ma <[email protected]>
Reviewed-on: https://go-review.googlesource.com/7400
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-on: https://go-review.googlesource.com/14248
Reviewed-by: Andrew Gerrand <[email protected]>
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
… non-zero len from growslice

Fixes golang#10135.

Change-Id: Ic4c5ab15bcb7b9c3fcc685a788d3b59c60c26e1e
Signed-off-by: Shenghou Ma <[email protected]>
Reviewed-on: https://go-review.googlesource.com/7400
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-on: https://go-review.googlesource.com/14248
Reviewed-by: Andrew Gerrand <[email protected]>
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 20, 2018
… non-zero len from growslice

Fixes golang#10135.

Change-Id: Ic4c5ab15bcb7b9c3fcc685a788d3b59c60c26e1e
Signed-off-by: Shenghou Ma <[email protected]>
Reviewed-on: https://go-review.googlesource.com/7400
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-on: https://go-review.googlesource.com/14248
Reviewed-by: Andrew Gerrand <[email protected]>
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
… non-zero len from growslice

Fixes golang#10135.

Change-Id: Ic4c5ab15bcb7b9c3fcc685a788d3b59c60c26e1e
Signed-off-by: Shenghou Ma <[email protected]>
Reviewed-on: https://go-review.googlesource.com/7400
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-on: https://go-review.googlesource.com/14248
Reviewed-by: Andrew Gerrand <[email protected]>
@rsc rsc unassigned minux Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants