mgo

Merge lp:~mwhudson/mgo/evaluation-order into lp:mgo/v2

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: 247
Proposed branch: lp:~mwhudson/mgo/evaluation-order
Merge into: lp:mgo/v2
Diff against target: 43 lines (+8/-4)
1 file modified
bson/decode.go (+8/-4)
To merge this branch: bzr merge lp:~mwhudson/mgo/evaluation-order
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Pending
Review via email: mp+194968@code.launchpad.net

Description of the change

bson: don't trust expression evaluation order

The evaluation order of

  end := d.i - 4 + int(d.readInt32())

differs when compiled with gccgo vs the gc toolchain, and is
apparently unspecified according to the spec.

To post a comment you must log in.
Revision history for this message
Dave Cheney (dave-cheney) wrote :

I've raised the question on the gccgo mailing list.

https://groups.google.com/d/msg/gofrontend-dev/y5g92hnEGfg/6tYHbfw-YtcJ

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

*** Submitted:

bson: don't trust expression evaluation order

The evaluation order of

  end := d.i - 4 + int(d.readInt32())

differs when compiled with gccgo vs the gc toolchain, and is
apparently unspecified according to the spec.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bson/decode.go'
2--- bson/decode.go 2013-08-04 23:00:08 +0000
3+++ bson/decode.go 2013-11-13 01:35:47 +0000
4@@ -214,7 +214,8 @@
5 panic("Unsupported document type for unmarshalling: " + out.Type().String())
6 }
7
8- end := d.i - 4 + int(d.readInt32())
9+ end := int(d.readInt32())
10+ end += d.i - 4
11 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {
12 corrupted()
13 }
14@@ -272,7 +273,8 @@
15 }
16
17 func (d *decoder) readArrayDocTo(out reflect.Value) {
18- end := d.i - 4 + int(d.readInt32())
19+ end := int(d.readInt32())
20+ end += d.i - 4
21 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {
22 corrupted()
23 }
24@@ -309,7 +311,8 @@
25 tmp := make([]reflect.Value, 0, 8)
26 elemType := t.Elem()
27
28- end := d.i - 4 + int(d.readInt32())
29+ end := int(d.readInt32())
30+ end += d.i - 4
31 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {
32 corrupted()
33 }
34@@ -381,7 +384,8 @@
35 }
36
37 func (d *decoder) readDocWith(f func(kind byte, name string)) {
38- end := d.i - 4 + int(d.readInt32())
39+ end := int(d.readInt32())
40+ end += d.i - 4
41 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {
42 corrupted()
43 }

Subscribers

People subscribed via source and target branches