Skip to content

encoding/gob: another problem with zero values in arrays #934

@gopherbot

Description

@gopherbot

by sonia1427:

What steps will reproduce the problem?

package main

import (
    "bytes"
    "fmt"
    "gob"
)

func main() {
    a := [3]int{2, 1, 0}
    b := new(bytes.Buffer)
    gob.NewEncoder(b).Encode(a)
    err := gob.NewDecoder(b).Decode(&a)
    fmt.Println(err)
}

What is the expected output?
<nil>

What do you see instead?
gob: length mismatch in decodeArray

What is your $GOOS?  $GOARCH?
linux amd64

Which revision are you using?  (hg identify)
20b5026b3332+ tip

Please provide any additional information below.
This is a little different than issue #459.  That regression test on arrays inside of
structs still passes.  This naked array (which wasn't allowed at the time of issue #459)
fails.  Also, it only seems to fail when a trailing element is zero.  Zeros at the
beginning and middle are okay.

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