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
=== modified file 'bson/decode.go'
--- bson/decode.go 2013-08-04 23:00:08 +0000
+++ bson/decode.go 2013-11-13 01:35:47 +0000
@@ -214,7 +214,8 @@
214 panic("Unsupported document type for unmarshalling: " + out.Type().String())214 panic("Unsupported document type for unmarshalling: " + out.Type().String())
215 }215 }
216216
217 end := d.i - 4 + int(d.readInt32())217 end := int(d.readInt32())
218 end += d.i - 4
218 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {219 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {
219 corrupted()220 corrupted()
220 }221 }
@@ -272,7 +273,8 @@
272}273}
273274
274func (d *decoder) readArrayDocTo(out reflect.Value) {275func (d *decoder) readArrayDocTo(out reflect.Value) {
275 end := d.i - 4 + int(d.readInt32())276 end := int(d.readInt32())
277 end += d.i - 4
276 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {278 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {
277 corrupted()279 corrupted()
278 }280 }
@@ -309,7 +311,8 @@
309 tmp := make([]reflect.Value, 0, 8)311 tmp := make([]reflect.Value, 0, 8)
310 elemType := t.Elem()312 elemType := t.Elem()
311313
312 end := d.i - 4 + int(d.readInt32())314 end := int(d.readInt32())
315 end += d.i - 4
313 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {316 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {
314 corrupted()317 corrupted()
315 }318 }
@@ -381,7 +384,8 @@
381}384}
382385
383func (d *decoder) readDocWith(f func(kind byte, name string)) {386func (d *decoder) readDocWith(f func(kind byte, name string)) {
384 end := d.i - 4 + int(d.readInt32())387 end := int(d.readInt32())
388 end += d.i - 4
385 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {389 if end <= d.i || end > len(d.in) || d.in[end-1] != '\x00' {
386 corrupted()390 corrupted()
387 }391 }

Subscribers

People subscribed via source and target branches