Skip to content

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

@taruti

Description

@taruti
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
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions