on master help sign in
Fix condition in allocate.
commit1ffeb135ed9ab7202251fa8d0228781bef968695 authorSam T <sta.cs.vsu@gmail.com> dateThu 14 Mar 2013, 19:36 (14 years ago) parent9841e2a
1 file changed+11−4
rts/idris_rts.c+11−4
rts/idris_rts.c+11−4
@@ -106,12 +106,19 @@ void* allocate(VM* vm, size_t size, int outerlock) {
106106 if ((size & 7)!=0) {
107107 size = 8 + ((size >> 3) << 3);
108108 }
109− if (vm -> heap_next + size < vm -> heap_end) {
110− vm->allocations += size + sizeof(size_t);
109+
110+ size_t chunk_size = size + sizeof(size_t);
111+
112+ if (vm -> heap_next + chunk_size < vm -> heap_end) {
113+ vm->allocations += chunk_size;
111114 void* ptr = (void*)(vm->heap_next + sizeof(size_t));
112− *((size_t*)(vm->heap_next)) = size + sizeof(size_t);
113− vm -> heap_next += size + sizeof(size_t);
115+ *((size_t*)(vm->heap_next)) = chunk_size;
116+ vm -> heap_next += chunk_size;
117+
118+ assert(vm->heap_next <= vm->heap_end);
119+
114120 memset(ptr, 0, size);
121+
115122 if (lock) { // not message passing
116123 pthread_mutex_unlock(&vm->alloc_lock);
117124 }