Browse Source

added error on hl_alloc_array(-1)

ncannasse 7 years ago
parent
commit
c4ac831d43
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/std/array.c

+ 3 - 1
src/std/array.c

@@ -23,7 +23,9 @@
 
 HL_PRIM varray *hl_alloc_array( hl_type *at, int size ) {
 	int esize = hl_type_size(at);
-	varray *a = (varray*)hl_gc_alloc_gen(&hlt_array, sizeof(varray) + esize*size, (hl_is_ptr(at) ? MEM_KIND_DYNAMIC : MEM_KIND_NOPTR) | MEM_ZERO);
+	varray *a;
+	if( size < 0 ) hl_error("Invalid array size");
+	a = (varray*)hl_gc_alloc_gen(&hlt_array, sizeof(varray) + esize*size, (hl_is_ptr(at) ? MEM_KIND_DYNAMIC : MEM_KIND_NOPTR) | MEM_ZERO);
 	a->t = &hlt_array;
 	a->at = at;
 	a->size = size;