tcc_realloc: auto "memory full" error
This commit is contained in:
6
libtcc.c
6
libtcc.c
@ -237,6 +237,8 @@ PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size)
|
|||||||
mem_cur_size -= malloc_usable_size(ptr);
|
mem_cur_size -= malloc_usable_size(ptr);
|
||||||
#endif
|
#endif
|
||||||
ptr1 = realloc(ptr, size);
|
ptr1 = realloc(ptr, size);
|
||||||
|
if (!ptr1 && size)
|
||||||
|
tcc_error("memory full");
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
/* NOTE: count not correct if alloc error, but not critical */
|
/* NOTE: count not correct if alloc error, but not critical */
|
||||||
mem_cur_size += malloc_usable_size(ptr1);
|
mem_cur_size += malloc_usable_size(ptr1);
|
||||||
@ -282,8 +284,6 @@ PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data)
|
|||||||
else
|
else
|
||||||
nb_alloc = nb * 2;
|
nb_alloc = nb * 2;
|
||||||
pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
|
pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
|
||||||
if (!pp)
|
|
||||||
tcc_error("memory full");
|
|
||||||
*ptab = pp;
|
*ptab = pp;
|
||||||
}
|
}
|
||||||
pp[nb++] = data;
|
pp[nb++] = data;
|
||||||
@ -377,8 +377,6 @@ ST_FUNC void section_realloc(Section *sec, unsigned long new_size)
|
|||||||
while (size < new_size)
|
while (size < new_size)
|
||||||
size = size * 2;
|
size = size * 2;
|
||||||
data = tcc_realloc(sec->data, size);
|
data = tcc_realloc(sec->data, size);
|
||||||
if (!data)
|
|
||||||
tcc_error("memory full");
|
|
||||||
memset(data + sec->data_allocated, 0, size - sec->data_allocated);
|
memset(data + sec->data_allocated, 0, size - sec->data_allocated);
|
||||||
sec->data = data;
|
sec->data = data;
|
||||||
sec->data_allocated = size;
|
sec->data_allocated = size;
|
||||||
|
|||||||
2
tccelf.c
2
tccelf.c
@ -836,8 +836,6 @@ static void put_got_offset(TCCState *s1, int index, unsigned long val)
|
|||||||
while (index >= n)
|
while (index >= n)
|
||||||
n *= 2;
|
n *= 2;
|
||||||
tab = tcc_realloc(s1->got_offsets, n * sizeof(unsigned long));
|
tab = tcc_realloc(s1->got_offsets, n * sizeof(unsigned long));
|
||||||
if (!tab)
|
|
||||||
tcc_error("memory full");
|
|
||||||
s1->got_offsets = tab;
|
s1->got_offsets = tab;
|
||||||
memset(s1->got_offsets + s1->nb_got_offsets, 0,
|
memset(s1->got_offsets + s1->nb_got_offsets, 0,
|
||||||
(n - s1->nb_got_offsets) * sizeof(unsigned long));
|
(n - s1->nb_got_offsets) * sizeof(unsigned long));
|
||||||
|
|||||||
6
tccpp.c
6
tccpp.c
@ -112,8 +112,6 @@ static void cstr_realloc(CString *cstr, int new_size)
|
|||||||
while (size < new_size)
|
while (size < new_size)
|
||||||
size = size * 2;
|
size = size * 2;
|
||||||
data = tcc_realloc(cstr->data_allocated, size);
|
data = tcc_realloc(cstr->data_allocated, size);
|
||||||
if (!data)
|
|
||||||
tcc_error("memory full");
|
|
||||||
cstr->data_allocated = data;
|
cstr->data_allocated = data;
|
||||||
cstr->size_allocated = size;
|
cstr->size_allocated = size;
|
||||||
cstr->data = data;
|
cstr->data = data;
|
||||||
@ -200,8 +198,6 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
|
|||||||
i = tok_ident - TOK_IDENT;
|
i = tok_ident - TOK_IDENT;
|
||||||
if ((i % TOK_ALLOC_INCR) == 0) {
|
if ((i % TOK_ALLOC_INCR) == 0) {
|
||||||
ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
|
ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
|
||||||
if (!ptable)
|
|
||||||
tcc_error("memory full");
|
|
||||||
table_ident = ptable;
|
table_ident = ptable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,8 +840,6 @@ static int *tok_str_realloc(TokenString *s)
|
|||||||
len = s->allocated_len * 2;
|
len = s->allocated_len * 2;
|
||||||
}
|
}
|
||||||
str = tcc_realloc(s->str, len * sizeof(int));
|
str = tcc_realloc(s->str, len * sizeof(int));
|
||||||
if (!str)
|
|
||||||
tcc_error("memory full");
|
|
||||||
s->allocated_len = len;
|
s->allocated_len = len;
|
||||||
s->str = str;
|
s->str = str;
|
||||||
return str;
|
return str;
|
||||||
|
|||||||
Reference in New Issue
Block a user