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

asn1 fails to marshal structures with multiple members (patch included) #515

Closed
taruti opened this issue Jan 11, 2010 · 3 comments
Closed

Comments

@taruti
Copy link
Contributor

taruti commented Jan 11, 2010

asn1 marshalling uses the forkableWriter, but unfortunately the
current code fails for any structures with more than one members.

To reproduce
type Foo struct { a,b int } 
asn1.Marshal(os.Stdout, Foo{1,2})
only marshals the last field of Foo.

The following patch fixes this:

diff -r e73e37a4a6da src/pkg/asn1/marshal.go
--- a/src/pkg/asn1/marshal.go   Sat Jan 09 09:47:45 2010 -0800
+++ b/src/pkg/asn1/marshal.go   Mon Jan 11 14:49:11 2010 +0200
@@ -29,6 +29,7 @@
 }
 
 func (f *forkableWriter) fork() (pre, post *forkableWriter) {
+   for f.post != nil { f = f.post }
    f.pre = newForkableWriter()
    f.post = newForkableWriter()
    return f.pre, f.post
@@ -61,7 +62,7 @@
        }
    }
 
-   if f.pre != nil {
+   if f.post != nil {
        nn, err = f.post.writeTo(out)
        n += nn
    }
@rsc
Copy link
Contributor

rsc commented Jan 11, 2010

Comment 1:

Owner changed to a...@golang.org.

@agl
Copy link
Contributor

agl commented Jan 12, 2010

Comment 2:

http://golang.org/cl/184079

Status changed to Started.

@agl
Copy link
Contributor

agl commented Jan 12, 2010

Comment 3:

This issue was closed by revision e7cceb8.

Status changed to Fixed.

Merged into issue #-.

@taruti taruti added the fixed label Jan 12, 2010
@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

4 participants