File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change 44
55 public __simple_malloc
66__simple_malloc:
7+ ; returns NULL when size is zero
78 pop bc
89 ex (sp),hl
910 push bc
1011 ld de,(_heap_ptr)
12+ dec hl
1113 add hl,de
1214 jr c,.null
13- ld bc,___heaptop
15+ ld bc,___heaptop-1
1416 sbc hl,bc
1517 jr nc,.null
1618 add hl,bc
1719 ld (_heap_ptr),hl
1820 ex de,hl
1921 ret
2022.null:
21- or a,a
22- sbc hl,hl
23- ret
24-
25- public __simple_free
26- __simple_free:
27- ret
28-
2923 public __simple_realloc
3024__simple_realloc:
3125 or a,a
3226 sbc hl,hl
27+ public __simple_free
28+ __simple_free:
3329 ret
3430
3531 section .data
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ void *_standard_malloc(size_t alloc_size)
2121
2222 /* add size of block header to real size */
2323 const size_t size = alloc_size + sizeof (block_t );
24- if (size < alloc_size )
24+ /* abort if alloc_size is 0 or size overflowed */
25+ if (size <= alloc_size )
2526 {
2627 return NULL ;
2728 }
You can’t perform that action at this time.
0 commit comments