summaryrefslogtreecommitdiff
path: root/toxcore/ping_array.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/ping_array.c')
-rw-r--r--toxcore/ping_array.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c
index 627f8d5a..a54ebfe2 100644
--- a/toxcore/ping_array.c
+++ b/toxcore/ping_array.c
@@ -57,20 +57,20 @@ struct Ping_Array {
57Ping_Array *ping_array_new(uint32_t size, uint32_t timeout) 57Ping_Array *ping_array_new(uint32_t size, uint32_t timeout)
58{ 58{
59 if (size == 0 || timeout == 0) { 59 if (size == 0 || timeout == 0) {
60 return NULL; 60 return nullptr;
61 } 61 }
62 62
63 Ping_Array *empty_array = (Ping_Array *)calloc(1, sizeof(Ping_Array)); 63 Ping_Array *empty_array = (Ping_Array *)calloc(1, sizeof(Ping_Array));
64 64
65 if (empty_array == NULL) { 65 if (empty_array == nullptr) {
66 return NULL; 66 return nullptr;
67 } 67 }
68 68
69 empty_array->entries = (Ping_Array_Entry *)calloc(size, sizeof(Ping_Array_Entry)); 69 empty_array->entries = (Ping_Array_Entry *)calloc(size, sizeof(Ping_Array_Entry));
70 70
71 if (empty_array->entries == NULL) { 71 if (empty_array->entries == nullptr) {
72 free(empty_array); 72 free(empty_array);
73 return NULL; 73 return nullptr;
74 } 74 }
75 75
76 empty_array->last_deleted = empty_array->last_added = 0; 76 empty_array->last_deleted = empty_array->last_added = 0;
@@ -82,7 +82,7 @@ Ping_Array *ping_array_new(uint32_t size, uint32_t timeout)
82static void clear_entry(Ping_Array *array, uint32_t index) 82static void clear_entry(Ping_Array *array, uint32_t index)
83{ 83{
84 free(array->entries[index].data); 84 free(array->entries[index].data);
85 array->entries[index].data = NULL; 85 array->entries[index].data = nullptr;
86 array->entries[index].length = 86 array->entries[index].length =
87 array->entries[index].time = 87 array->entries[index].time =
88 array->entries[index].ping_id = 0; 88 array->entries[index].ping_id = 0;
@@ -128,14 +128,14 @@ uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length)
128 ping_array_clear_timedout(array); 128 ping_array_clear_timedout(array);
129 uint32_t index = array->last_added % array->total_size; 129 uint32_t index = array->last_added % array->total_size;
130 130
131 if (array->entries[index].data != NULL) { 131 if (array->entries[index].data != nullptr) {
132 array->last_deleted = array->last_added - array->total_size; 132 array->last_deleted = array->last_added - array->total_size;
133 clear_entry(array, index); 133 clear_entry(array, index);
134 } 134 }
135 135
136 array->entries[index].data = malloc(length); 136 array->entries[index].data = malloc(length);
137 137
138 if (array->entries[index].data == NULL) { 138 if (array->entries[index].data == nullptr) {
139 return 0; 139 return 0;
140 } 140 }
141 141
@@ -184,7 +184,7 @@ int32_t ping_array_check(Ping_Array *array, uint8_t *data, size_t length, uint64
184 return -1; 184 return -1;
185 } 185 }
186 186
187 if (array->entries[index].data == NULL) { 187 if (array->entries[index].data == nullptr) {
188 return -1; 188 return -1;
189 } 189 }
190 190