on master help sign in
Fix condition in allocate.
1ffeb13Sam T
rts/idris_rts.c+11−4
@@ -106,12 +106,19 @@ void* allocate(VM* vm, size_t size, int outerlock) {
106 if ((size & 7)!=0) {
106 if ((size & 7)!=0) {
107 size = 8 + ((size >> 3) << 3);
107 size = 8 + ((size >> 3) << 3);
108 }
108 }
109+
110+ size_t chunk_size = size + sizeof(size_t);
111+
109− if (vm -> heap_next + size < vm -> heap_end) {
112+ if (vm -> heap_next + chunk_size < vm -> heap_end) {
110− vm->allocations += size + sizeof(size_t);
113+ vm->allocations += chunk_size;
111 void* ptr = (void*)(vm->heap_next + sizeof(size_t));
114 void* ptr = (void*)(vm->heap_next + sizeof(size_t));
112− *((size_t*)(vm->heap_next)) = size + sizeof(size_t);
115+ *((size_t*)(vm->heap_next)) = chunk_size;
113− vm -> heap_next += size + sizeof(size_t);
116+ vm -> heap_next += chunk_size;
117+
118+ assert(vm->heap_next <= vm->heap_end);
119+
114 memset(ptr, 0, size);
120 memset(ptr, 0, size);
121+
115 if (lock) { // not message passing
122 if (lock) { // not message passing
116 pthread_mutex_unlock(&vm->alloc_lock);
123 pthread_mutex_unlock(&vm->alloc_lock);
117 }
124 }