]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
fix: rotate_entfield_array_index_nodes deleting the old array caused expressions...
authorWolfgang Bumiller <blub@speed.at>
Sun, 3 Feb 2013 22:38:06 +0000 (23:38 +0100)
committerWolfgang Bumiller <blub@speed.at>
Sun, 3 Feb 2013 22:38:06 +0000 (23:38 +0100)
ast.c
parser.c

diff --git a/ast.c b/ast.c
index 7f6841fb96aea414e5d7f6afa78922b4f7d995f3..294c13b42dc175f369db95f6101868041b43a670 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -660,8 +660,10 @@ ast_array_index* ast_array_index_new(lex_ctx ctx, ast_expression *array, ast_exp
 
 void ast_array_index_delete(ast_array_index *self)
 {
-    ast_unref(self->array);
-    ast_unref(self->index);
+    if (self->array)
+        ast_unref(self->array);
+    if (self->index)
+        ast_unref(self->index);
     ast_expression_delete((ast_expression*)self);
     mem_d(self);
 }
index 90d73bae931ec3c9ceb4ea531c008edd8fc2c353..aa536c50ac8161f4cba91617781cfb2603c4aa7e 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -449,7 +449,7 @@ static sy_elem syparen(lex_ctx ctx, size_t off) {
  */
 static bool rotate_entfield_array_index_nodes(ast_expression **out)
 {
-    ast_array_index *index;
+    ast_array_index *index, *oldindex;
     ast_entfield    *entfield;
 
     ast_value       *field;
@@ -473,12 +473,16 @@ static bool rotate_entfield_array_index_nodes(ast_expression **out)
     sub    = index->index;
     entity = entfield->entity;
 
-    ast_delete(index);
+    oldindex = index;
 
     index = ast_array_index_new(ctx, (ast_expression*)field, sub);
     entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
     *out = (ast_expression*)entfield;
 
+    oldindex->array = NULL;
+    oldindex->index = NULL;
+    ast_delete(oldindex);
+
     return true;
 }