]> git.lizzy.rs Git - rust.git/commitdiff
Fix potential use-before-init bug in trans
authorTim Chevalier <chevalier@alum.wellesley.edu>
Tue, 12 Jul 2011 18:21:14 +0000 (11:21 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Tue, 12 Jul 2011 18:21:14 +0000 (11:21 -0700)
This was being masked by a bug in typestate (fixed in the next commit).

src/comp/middle/trans.rs

index e732a5b83e3f222dc8b66dbb1b8b447fbbf5a6d5..592757014316707eccadc1944febb69d7765c6ce 100644 (file)
@@ -7129,7 +7129,7 @@ fn anon_obj_field_to_obj_field(&ast::anon_obj_field f)
         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 anon_obj_field_to_obj_field(&ast::anon_obj_field f)
             // 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 anon_obj_field_to_obj_field(&ast::anon_obj_field f)
             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);