about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2011-07-12 11:21:14 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2011-07-12 11:21:14 -0700
commit0e594939aa032c074df925d03c7d1289d6c2efc2 (patch)
treee03079cc37f8b087f2243bc62136f33e309eaa67 /src/comp
parentbde52808f0fa6d44b7d738ba2e79a4192ccdd54b (diff)
downloadrust-0e594939aa032c074df925d03c7d1289d6c2efc2.tar.gz
rust-0e594939aa032c074df925d03c7d1289d6c2efc2.zip
Fix potential use-before-init bug in trans
This was being masked by a bug in typestate (fixed in the next commit).
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index e732a5b83e3..59275701431 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -7129,7 +7129,7 @@ fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj,
         methods = anon_obj.methods,
         dtor = none[@ast::method]);
 
-    let result with_obj_val;
+    let option::t[result] with_obj_val = none;
     let ty::t with_obj_ty;
     auto vtbl;
     alt (anon_obj.with_obj) {
@@ -7155,7 +7155,7 @@ fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj,
             // If with_obj (the object being extended) exists, translate it.
             // Translating with_obj returns a ValueRef (pointer to a 2-word
             // value) wrapped in a result.
-            with_obj_val = trans_expr(bcx, e);
+            with_obj_val = some(trans_expr(bcx, e));
 
             // TODO: What makes more sense to get the type of an expr --
             // calling ty::expr_ty(ccx.tcx, e) on it or calling
@@ -7332,9 +7332,13 @@ fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj,
             GEP_tup_like(bcx, body_ty, body.val,
                          ~[0, abi::obj_body_elt_with_obj]);
         bcx = body_with_obj.bcx;
-        bcx = copy_val(bcx, INIT, body_with_obj.val,
-                       with_obj_val.val,
-                       with_obj_ty).bcx;
+        alt (with_obj_val) {
+            case (some(?v)) {
+                bcx = copy_val(bcx, INIT, body_with_obj.val,
+                               v.val, with_obj_ty).bcx;
+            }
+            case (_) {}
+        }
 
         // Store box ptr in outer pair.
         auto p = bcx.build.PointerCast(box.val, llbox_ty);