summaryrefslogtreecommitdiff
path: root/toxcore/list.c
diff options
context:
space:
mode:
authornotsecure <notsecure@marek.ca>2014-05-19 17:53:29 -0400
committernotsecure <notsecure@marek.ca>2014-05-19 17:53:29 -0400
commit410294da4882fa7e66e0acc8e323e00dcb2618f9 (patch)
tree16121d985cfb894cd3efa9f9c6e16470838bdbf6 /toxcore/list.c
parentfe66fcc7e4053a7ec7e59d22a1e4847980c90d6a (diff)
style, failure check on realloc
Diffstat (limited to 'toxcore/list.c')
-rw-r--r--toxcore/list.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/toxcore/list.c b/toxcore/list.c
index 2ca9b175..2494016b 100644
--- a/toxcore/list.c
+++ b/toxcore/list.c
@@ -36,7 +36,7 @@
36 * -some considerations since the array size is never perfect 36 * -some considerations since the array size is never perfect
37 */ 37 */
38 38
39 #define INDEX(i) (-i -1) 39#define INDEX(i) (-i -1)
40 40
41/* Find data in list 41/* Find data in list
42 * 42 *
@@ -75,8 +75,7 @@ static int find(LIST *list, void *data)
75 } 75 }
76 76
77 delta = (delta) / 2; 77 delta = (delta) / 2;
78 if(delta == 0) 78 if(delta == 0) {
79 {
80 delta = 1; 79 delta = 1;
81 d = 1; 80 d = 1;
82 } 81 }
@@ -143,6 +142,11 @@ int list_add(LIST *list, void *data, int id)
143 list->data = realloc(list->data, list->size * (list->n + 1)); 142 list->data = realloc(list->data, list->size * (list->n + 1));
144 list->ids = realloc(list->ids, sizeof(int) * (list->n + 1)); 143 list->ids = realloc(list->ids, sizeof(int) * (list->n + 1));
145 144
145 if(!list->data || !list->ids)
146 {
147 return 0;
148 }
149
146 //insert data to element array 150 //insert data to element array
147 memmove(list->data + (i + 1) * list->size, list->data + i * list->size, (list->n - i) * list->size); 151 memmove(list->data + (i + 1) * list->size, list->data + i * list->size, (list->n - i) * list->size);
148 memcpy(list->data + i * list->size, data, list->size); 152 memcpy(list->data + i * list->size, data, list->size);