]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ir.c
ir_value now checks if a name was specified
[xonotic/gmqcc.git] / ir.c
diff --git a/ir.c b/ir.c
index 0be4d05179916b09255a6570857a32591e84c344..1f9a80db3d213436fce94ad993f45dd46d1ab31b 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -462,7 +462,7 @@ ir_block* ir_block_new(ir_function* owner, const char *name)
     memset(self, 0, sizeof(*self));
 
     self->label = NULL;
-    if (!ir_block_set_label(self, name)) {
+    if (name && !ir_block_set_label(self, name)) {
         mem_d(self);
         return NULL;
     }
@@ -491,7 +491,7 @@ MEM_VEC_FUNCTIONS_ALL(ir_block, ir_value*, living)
 void ir_block_delete(ir_block* self)
 {
     size_t i;
-    mem_d(self->label);
+    if (self->label) mem_d(self->label);
     for (i = 0; i != self->instr_count; ++i)
         ir_instr_delete(self->instr[i]);
     MEM_VECTOR_CLEAR(self, instr);
@@ -630,7 +630,11 @@ ir_value* ir_value_var(const char *name, int storetype, int vtype)
     self->context.file = "<@no context>";
     self->context.line = 0;
     self->name = NULL;
-    ir_value_set_name(self, name);
+    if (name && !ir_value_set_name(self, name)) {
+        irerror(self->context, "out of memory");
+        mem_d(self);
+        return NULL;
+    }
 
     memset(&self->constval, 0, sizeof(self->constval));
     memset(&self->code,     0, sizeof(self->code));
@@ -723,11 +727,12 @@ void ir_value_delete(ir_value* self)
     mem_d(self);
 }
 
-void ir_value_set_name(ir_value *self, const char *name)
+bool ir_value_set_name(ir_value *self, const char *name)
 {
     if (self->name)
         mem_d((void*)self->name);
     self->name = util_strdup(name);
+    return !!self->name;
 }
 
 bool ir_value_set_float(ir_value *self, float f)