We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 30a3ecc commit 132611aCopy full SHA for 132611a
src/libc/allocator_simple.src
@@ -4,13 +4,15 @@
4
5
public __simple_malloc
6
__simple_malloc:
7
+ ; returns NULL when size is zero
8
pop bc
9
ex (sp),hl
10
push bc
11
ld de,(_heap_ptr)
12
+ dec hl
13
add hl,de
14
jr c,.null
- ld bc,___heaptop
15
+ ld bc,___heaptop-1
16
sbc hl,bc
17
jr nc,.null
18
add hl,bc
src/libc/allocator_standard.c
@@ -21,7 +21,8 @@ void *_standard_malloc(size_t alloc_size)
21
22
/* add size of block header to real size */
23
const size_t size = alloc_size + sizeof(block_t);
24
- if (size < alloc_size)
+ /* abort if alloc_size is 0 or size overflowed */
25
+ if (size <= alloc_size)
26
{
27
return NULL;
28
}
0 commit comments