diff options
author | notsecure <notsecure@marek.ca> | 2014-05-19 19:07:47 -0400 |
---|---|---|
committer | notsecure <notsecure@marek.ca> | 2014-05-19 19:07:47 -0400 |
commit | 1810d1e20e0755e17e6be81a6ad4ea0d8d0d2e27 (patch) | |
tree | 9eb051f189e3e28dbef6067a17563e04b2a5eff5 /toxcore/list.c | |
parent | 9ae2fde0b9326f600571e3d0e30f442e51e68e1e (diff) |
proper realloc failure check
Diffstat (limited to 'toxcore/list.c')
-rw-r--r-- | toxcore/list.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/toxcore/list.c b/toxcore/list.c index 4d83c7be..6bd6230c 100644 --- a/toxcore/list.c +++ b/toxcore/list.c | |||
@@ -144,11 +144,22 @@ int list_add(LIST *list, void *data, int id) | |||
144 | i = -i - 1; | 144 | i = -i - 1; |
145 | 145 | ||
146 | //increase the size of the arrays by one | 146 | //increase the size of the arrays by one |
147 | list->data = realloc(list->data, list->size * (list->n + 1)); | 147 | void *p; |
148 | list->ids = realloc(list->ids, sizeof(int) * (list->n + 1)); | ||
149 | 148 | ||
150 | if (!list->data || !list->ids) { | 149 | p = realloc(list->data, list->size * (list->n + 1)); |
150 | |||
151 | if (!p) { | ||
152 | return 0; | ||
153 | } else { | ||
154 | list->data = p; | ||
155 | } | ||
156 | |||
157 | p = realloc(list->ids, sizeof(int) * (list->n + 1)); | ||
158 | |||
159 | if (!p) { | ||
151 | return 0; | 160 | return 0; |
161 | } else { | ||
162 | list->ids = p; | ||
152 | } | 163 | } |
153 | 164 | ||
154 | //insert data to element array | 165 | //insert data to element array |