History

tcc_realloc: auto "memory full" error

grischka committed 14 years ago

Commit f1b5c2e1 parent 3c59f843 files · +2 −12Browse files

Unified · Split

3 files
  1. libtcc.c +2 −4
  2. tccelf.c +0 −2
  3. tccpp.c +0 −6
libtcc.c+2−4
@@ -237,6 +237,8 @@ PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size) · 236 unmodified lines
237237 mem_cur_size -= malloc_usable_size(ptr);
238238 #endif
239239 ptr1 = realloc(ptr, size);
240+ if (!ptr1 && size)
241+ tcc_error("memory full");
240242 #ifdef MEM_DEBUG
241243 /* NOTE: count not correct if alloc error, but not critical */
242244 mem_cur_size += malloc_usable_size(ptr1);
@@ -282,8 +284,6 @@ PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data) · 39 unmodified lines
282284 else
283285 nb_alloc = nb * 2;
284286 pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
285− if (!pp)
286− tcc_error("memory full");
287287 *ptab = pp;
288288 }
289289 pp[nb++] = data;
@@ -377,8 +377,6 @@ ST_FUNC void section_realloc(Section *sec, unsigned long new_size) · 87 unmodified lines
377377 while (size < new_size)
378378 size = size * 2;
379379 data = tcc_realloc(sec->data, size);
380− if (!data)
381− tcc_error("memory full");
382380 memset(data + sec->data_allocated, 0, size - sec->data_allocated);
383381 sec->data = data;
384382 sec->data_allocated = size;
tccelf.c+0−2
@@ -836,8 +836,6 @@ static void put_got_offset(TCCState *s1, int index, unsigned long val) · 835 unmodified lines
836836 while (index >= n)
837837 n *= 2;
838838 tab = tcc_realloc(s1->got_offsets, n * sizeof(unsigned long));
839− if (!tab)
840− tcc_error("memory full");
841839 s1->got_offsets = tab;
842840 memset(s1->got_offsets + s1->nb_got_offsets, 0,
843841 (n - s1->nb_got_offsets) * sizeof(unsigned long));
tccpp.c+0−6
@@ -112,8 +112,6 @@ static void cstr_realloc(CString *cstr, int new_size) · 111 unmodified lines
112112 while (size < new_size)
113113 size = size * 2;
114114 data = tcc_realloc(cstr->data_allocated, size);
115− if (!data)
116− tcc_error("memory full");
117115 cstr->data_allocated = data;
118116 cstr->size_allocated = size;
119117 cstr->data = data;
@@ -200,8 +198,6 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) · 80 unmodified lines
200198 i = tok_ident - TOK_IDENT;
201199 if ((i % TOK_ALLOC_INCR) == 0) {
202200 ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
203− if (!ptable)
204− tcc_error("memory full");
205201 table_ident = ptable;
206202 }
207203
@@ -844,8 +840,6 @@ static int *tok_str_realloc(TokenString *s) · 636 unmodified lines
844840 len = s->allocated_len * 2;
845841 }
846842 str = tcc_realloc(s->str, len * sizeof(int));
847− if (!str)
848− tcc_error("memory full");
849843 s->allocated_len = len;
850844 s->str = str;
851845 return str;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t