Merge pull request #158 from regeda/invalid_indirect_of_pointer_on_array

fix invalid indirect of a pointer on a array
This commit is contained in:
Vasily Romanov
2018-03-20 16:17:58 +03:00
committed by GitHub
4 changed files with 21 additions and 2 deletions
+1 -1
View File
@@ -180,7 +180,7 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field
fmt.Fprintln(g.out, ws+" for !in.IsDelim(']') {")
fmt.Fprintln(g.out, ws+" if "+iterVar+" < "+fmt.Sprint(length)+" {")
if err := g.genTypeDecoder(elem, out+"["+iterVar+"]", tags, indent+3); err != nil {
if err := g.genTypeDecoder(elem, "("+out+")["+iterVar+"]", tags, indent+3); err != nil {
return err
}
+1 -1
View File
@@ -175,7 +175,7 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT
fmt.Fprintln(g.out, ws+" out.RawByte(',')")
fmt.Fprintln(g.out, ws+" }")
if err := g.genTypeEncoder(elem, in+"["+iVar+"]", tags, indent+1, false); err != nil {
if err := g.genTypeEncoder(elem, "("+in+")["+iVar+"]", tags, indent+1, false); err != nil {
return err
}
+1
View File
@@ -49,6 +49,7 @@ var testCases = []struct {
{&mapUint64StringValue, mapUint64StringValueString},
{&mapUintptrStringValue, mapUintptrStringValueString},
{&intKeyedMapStructValue, intKeyedMapStructValueString},
{&intArrayStructValue, intArrayStructValueString},
}
func TestMarshal(t *testing.T) {
+18
View File
@@ -766,3 +766,21 @@ var intKeyedMapStructValueString = `{` +
`"foo":{"42":"life"},` +
`"bar":{"32":{"354634382":"life"}}` +
`}`
type IntArray [2]int
//easyjson:json
type IntArrayStruct struct {
Pointer *IntArray `json:"pointer"`
Value IntArray `json:"value"`
}
var intArrayStructValue = IntArrayStruct{
Pointer: &IntArray{1, 2},
Value: IntArray{1, 2},
}
var intArrayStructValueString = `{` +
`"pointer":[1,2],` +
`"value":[1,2]` +
`}`