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