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
237 mem_cur_size -= malloc_usable_size(ptr);237 mem_cur_size -= malloc_usable_size(ptr);
238#endif238#endif
239 ptr1 = realloc(ptr, size);239 ptr1 = realloc(ptr, size);
240 if (!ptr1 && size)
241 tcc_error("memory full");
240#ifdef MEM_DEBUG242#ifdef MEM_DEBUG
241 /* NOTE: count not correct if alloc error, but not critical */243 /* NOTE: count not correct if alloc error, but not critical */
242 mem_cur_size += malloc_usable_size(ptr1);244 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
282 else284 else
283 nb_alloc = nb * 2;285 nb_alloc = nb * 2;
284 pp = tcc_realloc(pp, nb_alloc * sizeof(void *));286 pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
285 if (!pp)
286 tcc_error("memory full");
287 *ptab = pp;287 *ptab = pp;
288 }288 }
289 pp[nb++] = data;289 pp[nb++] = data;
@@ -377,8 +377,6 @@ ST_FUNC void section_realloc(Section *sec, unsigned long new_size) · 87 unmodified lines
377 while (size < new_size)377 while (size < new_size)
378 size = size * 2;378 size = size * 2;
379 data = tcc_realloc(sec->data, size);379 data = tcc_realloc(sec->data, size);
380 if (!data)
381 tcc_error("memory full");
382 memset(data + sec->data_allocated, 0, size - sec->data_allocated);380 memset(data + sec->data_allocated, 0, size - sec->data_allocated);
383 sec->data = data;381 sec->data = data;
384 sec->data_allocated = size;382 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
836 while (index >= n)836 while (index >= n)
837 n *= 2;837 n *= 2;
838 tab = tcc_realloc(s1->got_offsets, n * sizeof(unsigned long));838 tab = tcc_realloc(s1->got_offsets, n * sizeof(unsigned long));
839 if (!tab)
840 tcc_error("memory full");
841 s1->got_offsets = tab;839 s1->got_offsets = tab;
842 memset(s1->got_offsets + s1->nb_got_offsets, 0,840 memset(s1->got_offsets + s1->nb_got_offsets, 0,
843 (n - s1->nb_got_offsets) * sizeof(unsigned long));841 (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
112 while (size < new_size)112 while (size < new_size)
113 size = size * 2;113 size = size * 2;
114 data = tcc_realloc(cstr->data_allocated, size);114 data = tcc_realloc(cstr->data_allocated, size);
115 if (!data)
116 tcc_error("memory full");
117 cstr->data_allocated = data;115 cstr->data_allocated = data;
118 cstr->size_allocated = size;116 cstr->size_allocated = size;
119 cstr->data = data;117 cstr->data = data;
@@ -200,8 +198,6 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) · 80 unmodified lines
200 i = tok_ident - TOK_IDENT;198 i = tok_ident - TOK_IDENT;
201 if ((i % TOK_ALLOC_INCR) == 0) {199 if ((i % TOK_ALLOC_INCR) == 0) {
202 ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));200 ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
203 if (!ptable)
204 tcc_error("memory full");
205 table_ident = ptable;201 table_ident = ptable;
206 }202 }
207 203
@@ -844,8 +840,6 @@ static int *tok_str_realloc(TokenString *s) · 636 unmodified lines
844 len = s->allocated_len * 2;840 len = s->allocated_len * 2;
845 }841 }
846 str = tcc_realloc(s->str, len * sizeof(int));842 str = tcc_realloc(s->str, len * sizeof(int));
847 if (!str)
848 tcc_error("memory full");
849 s->allocated_len = len;843 s->allocated_len = len;
850 s->str = str;844 s->str = str;
851 return str;845 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