mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-22 02:11:19 +00:00
[ruamoko] Check for null when allocating objects
It's difficult for progs to check for errors when the engine crashes out from underneath them :P
This commit is contained in:
parent
a7ac188d1d
commit
eebf3158fa
1 changed files with 11 additions and 7 deletions
|
@ -1700,12 +1700,14 @@ class_create_instance (progs_t *pr, pr_class_t *class)
|
|||
{
|
||||
int size = (class->instance_size + 1) * sizeof (pr_type_t);
|
||||
pr_type_t *mem;
|
||||
pr_id_t *id;
|
||||
pr_id_t *id = 0;
|
||||
|
||||
mem = PR_Zone_TagMalloc (pr, size, class->name);
|
||||
memset (mem, 0, size);
|
||||
id = (pr_id_t *) (mem + 1);
|
||||
id->class_pointer = PR_SetPointer (pr, class);
|
||||
if (mem) {
|
||||
memset (mem, 0, size);
|
||||
id = (pr_id_t *) (mem + 1);
|
||||
id->class_pointer = PR_SetPointer (pr, class);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -1832,9 +1834,11 @@ rua_object_copy (progs_t *pr)
|
|||
pr_id_t *id;
|
||||
|
||||
id = class_create_instance (pr, class);
|
||||
memcpy (id, object, sizeof (pr_type_t) * class->instance_size);
|
||||
// copy the retain count
|
||||
((pr_type_t *) id)[-1] = ((pr_type_t *) object)[-1];
|
||||
if (id) {
|
||||
memcpy (id, object, sizeof (pr_type_t) * class->instance_size);
|
||||
// copy the retain count
|
||||
((pr_type_t *) id)[-1] = ((pr_type_t *) object)[-1];
|
||||
}
|
||||
RETURN_POINTER (pr, id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue