Skip to content

Commit

Permalink
FIX: Java marshalFit code corruption with inner objects. (issue #66)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascaldekloe committed Jun 18, 2020
1 parent 29bdba8 commit c03fd8f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
27 changes: 13 additions & 14 deletions java.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,19 @@ import java.nio.BufferUnderflowException;
*/
public int marshalFit() {
long n = 1L
{{- range .Fields}} + {{if eq .Type "bool"}}1
{{- else if eq .Type "uint8"}}2
{{- else if eq .Type "uint16"}}3
{{- else if eq .Type "uint32"}}5
{{- else if eq .Type "uint64"}}9
{{- else if eq .Type "int32"}}6
{{- else if eq .Type "int64"}}10
{{- else if eq .Type "float32"}}{{if .TypeList}}6 + (long)this.{{.NameNative}}.length * 4{{else}}5{{end}}
{{- else if eq .Type "float64"}}{{if .TypeList}}6 + (long)this.{{.NameNative}}.length * 8{{else}}9{{end}}
{{- else if eq .Type "timestamp"}}13
{{- else if eq .Type "text"}}6 + {{if .TypeList}}(long)this.{{.NameNative}}.length * 6{{else}}(long)this.{{.NameNative}}.length() * 3{{end}}
{{- else if eq .Type "binary"}}6 + (long)this.{{.NameNative}}.length{{if .TypeList}} * 6{{end}}
{{- else if .TypeList}}6
{{- else}}
{{- range .Fields}}{{if eq .Type "bool"}} + 1
{{- else if eq .Type "uint8"}} + 2
{{- else if eq .Type "uint16"}} + 3
{{- else if eq .Type "uint32"}} + 5
{{- else if eq .Type "uint64"}} + 9
{{- else if eq .Type "int32"}} + 6
{{- else if eq .Type "int64"}} + 10
{{- else if eq .Type "float32"}}{{if .TypeList}} + 6 + (long)this.{{.NameNative}}.length * 4{{else}} + 5{{end}}
{{- else if eq .Type "float64"}}{{if .TypeList}} + 6 + (long)this.{{.NameNative}}.length * 8{{else}} + 9{{end}}
{{- else if eq .Type "timestamp"}} + 13
{{- else if eq .Type "text"}} + 6{{if .TypeList}} + (long)this.{{.NameNative}}.length * 6{{else}} + (long)this.{{.NameNative}}.length() * 3{{end}}
{{- else if eq .Type "binary"}} + 6 + (long)this.{{.NameNative}}.length{{if .TypeList}} * 6{{end}}
{{- else if .TypeList}} + 6
{{- end}}{{end}};
{{- range .Fields}}{{if eq .Type "bool"}}
Expand Down
2 changes: 1 addition & 1 deletion java/gen/O.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public O next() throws IOException {
* @return the number of bytes.
*/
public int marshalFit() {
long n = 1L + 1 + 5 + 9 + 6 + 10 + 5 + 9 + 13 + 6 + (long)this.s.length() * 3 + 6 + (long)this.a.length + + 6 + 6 + (long)this.ss.length * 6 + 6 + (long)this.as.length * 6 + 2 + 3 + 6 + (long)this.f32s.length * 4 + 6 + (long)this.f64s.length * 8;
long n = 1L + 1 + 5 + 9 + 6 + 10 + 5 + 9 + 13 + 6 + (long)this.s.length() * 3 + 6 + (long)this.a.length + 6 + 6 + (long)this.ss.length * 6 + 6 + (long)this.as.length * 6 + 2 + 3 + 6 + (long)this.f32s.length * 4 + 6 + (long)this.f64s.length * 8;
if (this.o != null) n += 1 + (long)this.o.marshalFit();
for (O o : this.os) {
if (o == null) n++;
Expand Down
5 changes: 5 additions & 0 deletions testdata/break.colf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ type int struct {
throw []class
finally []void.class
}

// Issue66 is a regression test.
type Issue66 struct {
value class
}

0 comments on commit c03fd8f

Please sign in to comment.