[macruby-changes] [4419] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Aug 10 17:55:42 PDT 2010


Revision: 4419
          http://trac.macosforge.org/projects/ruby/changeset/4419
Author:   lsansonetti at apple.com
Date:     2010-08-10 17:55:41 -0700 (Tue, 10 Aug 2010)
Log Message:
-----------
don't crash in case rb_vm_keep_vars is called with no variables

Modified Paths:
--------------
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/vm.cpp

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2010-08-11 00:30:14 UTC (rev 4418)
+++ MacRuby/trunk/compiler.cpp	2010-08-11 00:55:41 UTC (rev 4419)
@@ -2488,7 +2488,8 @@
 
     bb = notNullBB;
 
-    // params must be filled each time because in AOT mode it contains instructions
+    // params must be filled each time because in AOT mode it contains
+    // instructions
     std::vector<Value *> params;
     params.push_back(new LoadInst(current_var_uses, "", bb));
     params.push_back(NULL);

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2010-08-11 00:30:14 UTC (rev 4418)
+++ MacRuby/trunk/vm.cpp	2010-08-11 00:55:41 UTC (rev 4419)
@@ -2989,23 +2989,26 @@
 {
     rb_vm_var_uses *current = uses;
 
-    if ((current == NULL) || (current->uses_count == 0)) {
+    if (current == NULL || current->uses_count == 0) {
 	// there's no use alive so nothing to do
 	return;
     }
 
-    rb_vm_kept_local *locals = (rb_vm_kept_local *)xmalloc(
-	    sizeof(rb_vm_kept_local)*lvars_size);
+    rb_vm_kept_local *locals = NULL;
+    if (lvars_size > 0) {
+	locals = (rb_vm_kept_local *)xmalloc(sizeof(rb_vm_kept_local)
+		* lvars_size);
 
-    va_list ar;
-    va_start(ar, lvars_size);
-    for (int i = 0; i < lvars_size; ++i) {
-	locals[i].name = va_arg(ar, ID);
-	locals[i].stack_address = va_arg(ar, VALUE *);
-	GC_WB(&locals[i].new_address, (VALUE *)xmalloc(sizeof(VALUE)));
-	GC_WB(locals[i].new_address, *locals[i].stack_address);
+	va_list ar;
+	va_start(ar, lvars_size);
+	for (int i = 0; i < lvars_size; ++i) {
+	    locals[i].name = va_arg(ar, ID);
+	    locals[i].stack_address = va_arg(ar, VALUE *);
+	    GC_WB(&locals[i].new_address, (VALUE *)xmalloc(sizeof(VALUE)));
+	    GC_WB(locals[i].new_address, *locals[i].stack_address);
+	}
+	va_end(ar);
     }
-    va_end(ar);
 
     while (current != NULL) {
 	for (int use_index = 0; use_index < current->uses_count; ++use_index) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100810/570a4a07/attachment.html>


More information about the macruby-changes mailing list