Index: exec.c ================================================================== --- exec.c +++ exec.c @@ -11,10 +11,11 @@ #include "sqlite3.h" #include "smallxrm.h" #include "heromesh.h" #include "instruc.h" +Uint32 max_objects; Uint32 generation_number; Object**objects; Uint32 nobjects; Value globals[0x800]; Uint32 firstobj=VOIDLINK; @@ -62,14 +63,17 @@ } } #define OBJECT_ARRAY_BLOCK 256 Uint32 objalloc(Uint16 c) { - // c must be a valid (nonzero) class number, and not a class with CF_GROUP, CF_NOCLASS1, or CF_NOCLASS2 flags. + // Allocates a new object of the given class; links into the event list but not into the playfield. + // Does not send any messages or otherwise notify anyone that it has been created. + // Returns VOIDLINK if object cannot be created. Uint32 n; Class*cl=classes[c]; Object*o=calloc(1,sizeof(Object)+cl->uservars*sizeof(Value)); + if(!c || !cl || cl->cflags&(CF_GROUP|CF_NOCLASS1|CF_NOCLASS2)) goto bad; if(!o) fatal("Allocation failed\n"); o->class=c; o->generation=generation_number; #define C(x) o->x=cl->x; C(height) C(weight) C(climb) C(density) C(volume) C(strength) C(arrivals) C(departures) C(temperature) @@ -83,11 +87,11 @@ o->misc7=NVALUE(cl->misc7); if(nobjects) for(n=nobjects-1;;n--) { if(!objects[n]) goto found; if(!n) break; } - if(nobjects>=0xFFFF0000L) fatal("Too many objects\n"); + if(nobjects>=max_objects) goto bad; objects=realloc(objects,(nobjects+OBJECT_ARRAY_BLOCK)*sizeof(Object*)); if(!objects) fatal("Allocation failed\n"); for(n=nobjects;n