Skip to content

Commit 822743c

Browse files
Merge pull request #7 from ANLAB-KAIST/warning-fix
fix: discarded-qualifiers & pointer comparison warnings
2 parents 96450f3 + 438d894 commit 822743c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tinyalloc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct {
2626
} Heap;
2727

2828
static Heap *heap = NULL;
29-
static void *heap_limit = NULL;
29+
static const void *heap_limit = NULL;
3030
static size_t heap_split_thresh;
3131
static size_t heap_alignment;
3232
static size_t heap_max_blocks;
@@ -123,7 +123,7 @@ bool ta_init(const void *base, const void *limit, const size_t heap_blocks, cons
123123
heap->used = NULL;
124124
heap->fresh = heap->blocks;
125125
heap->top = (size_t)base + sizeof(Heap) + heap_blocks * sizeof(Block);
126-
heap->blocks = base + sizeof(Heap);
126+
heap->blocks = (Block*) (base + sizeof(Heap));
127127

128128
Block *block = heap->blocks;
129129
size_t i = heap_max_blocks - 1;
@@ -163,7 +163,7 @@ static Block *alloc_block(size_t num) {
163163
size_t top = heap->top;
164164
num = (num + heap_alignment - 1) & -heap_alignment;
165165
while (ptr != NULL) {
166-
const int is_top = ((size_t)ptr->addr + ptr->size >= top) && ((size_t)ptr->addr + num <= heap_limit);
166+
const int is_top = ((size_t)ptr->addr + ptr->size >= top) && ((size_t)ptr->addr + num <= (size_t)heap_limit);
167167
if (is_top || ptr->size >= num) {
168168
if (prev != NULL) {
169169
prev->next = ptr->next;
@@ -202,7 +202,7 @@ static Block *alloc_block(size_t num) {
202202
// no matching free blocks
203203
// see if any other blocks available
204204
size_t new_top = top + num;
205-
if (heap->fresh != NULL && new_top <= heap_limit) {
205+
if (heap->fresh != NULL && new_top <= (size_t)heap_limit) {
206206
ptr = heap->fresh;
207207
heap->fresh = ptr->next;
208208
ptr->addr = (void *)top;

0 commit comments

Comments
 (0)