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

panic in StringVector.Data() #294

Closed
gopherbot opened this issue Nov 22, 2009 · 3 comments
Closed

panic in StringVector.Data() #294

gopherbot opened this issue Nov 22, 2009 · 3 comments

Comments

@gopherbot
Copy link
Contributor

by bslesinsky:

What steps will reproduce the problem?

Compile and run:

package main

import (
    "container/vector";
    "fmt"
)

func main() {
    x := vector.NewStringVector(2);
    x.Push("hello ");
    x.Push("world");
    for s := range(x.Data()) {
        fmt.Print(s)
    }
}


What is the expected output? What do you see instead?

It should print "hello world". Instead:

$ ./8.out
interface is nil, not string
throw: interface conversion

panic PC=0xa4f10
throw+0x46 /Users/skybrian/go/src/pkg/runtime/runtime.c:74
    throw(0x4839f, 0x35c4c)
runtime·ifaceE2T+0x48 /Users/skybrian/go/src/pkg/runtime/iface.c:262
    runtime·ifaceE2T(0x4816c, 0x0, 0x0)
vector·*StringVector·Data+0xd4
/Users/skybrian/go/src/pkg/container/vector/stringvector.go:42
    vector·*StringVector·Data(0xa12b0, 0x48014, 0x5)
main·main+0x65 /Users/skybrian/tmp/bug.go:12
    main·main()
mainstart+0xf /Users/skybrian/go/src/pkg/runtime/386/asm.s:81
    mainstart()
goexit /Users/skybrian/go/src/pkg/runtime/proc.c:135
    goexit()

What is your $GOOS?  $GOARCH?

$ echo $GOOS $GOARCH
darwin 386

Which revision are you using?  (hg identify)

$ hg identify
44699e529c44+ tip
@griesemer
Copy link
Contributor

Comment 1:

Owner changed to g...@golang.org.

Status changed to Accepted.

@griesemer
Copy link
Contributor

Comment 2:

There are two issues here:
1) After allocating a new vector with NewStringVector(2), that vector already contains 2
elements. Printing it 
should print 4 strings ("", "", "hello ", "world").
2) StringVector (and IntVector) is not correctly initializing elements that are added
implicitly as part of a 
resize.
Will fix this by changing the vector interface:
- remove NewXVector since its parameter is confusing and new(vector.XVector) is a better
idiom to use
- rename Init to Resize with an extra capacity parameter

@griesemer
Copy link
Contributor

Comment 3:

This issue was closed by revision 001a8b1.

Status changed to Fixed.

Merged into issue #-.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
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

2 participants