summaryrefslogtreecommitdiff
path: root/toxcore/ping_array.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-08-31 19:12:19 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-08-31 20:04:16 +0100
commit633da98ae69866efb195e00d9a3a22ace6bada66 (patch)
tree875535f3d2257c4ea5bb97a553b2f1beab4a1590 /toxcore/ping_array.c
parent6356eb4e4fe407fa7870f2a685d0d08b5c2ec5bb (diff)
Add braces to all if statements.
Diffstat (limited to 'toxcore/ping_array.c')
-rw-r--r--toxcore/ping_array.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c
index 93dade05..59eb7018 100644
--- a/toxcore/ping_array.c
+++ b/toxcore/ping_array.c
@@ -46,8 +46,9 @@ static void ping_array_clear_timedout(Ping_Array *array)
46 while (array->last_deleted != array->last_added) { 46 while (array->last_deleted != array->last_added) {
47 uint32_t index = array->last_deleted % array->total_size; 47 uint32_t index = array->last_deleted % array->total_size;
48 48
49 if (!is_timeout(array->entries[index].time, array->timeout)) 49 if (!is_timeout(array->entries[index].time, array->timeout)) {
50 break; 50 break;
51 }
51 52
52 clear_entry(array, index); 53 clear_entry(array, index);
53 ++array->last_deleted; 54 ++array->last_deleted;
@@ -71,8 +72,9 @@ uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length)
71 72
72 array->entries[index].data = malloc(length); 73 array->entries[index].data = malloc(length);
73 74
74 if (array->entries[index].data == NULL) 75 if (array->entries[index].data == NULL) {
75 return 0; 76 return 0;
77 }
76 78
77 memcpy(array->entries[index].data, data, length); 79 memcpy(array->entries[index].data, data, length);
78 array->entries[index].length = length; 80 array->entries[index].length = length;
@@ -83,8 +85,9 @@ uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length)
83 ping_id *= array->total_size; 85 ping_id *= array->total_size;
84 ping_id += index; 86 ping_id += index;
85 87
86 if (ping_id == 0) 88 if (ping_id == 0) {
87 ping_id += array->total_size; 89 ping_id += array->total_size;
90 }
88 91
89 array->entries[index].ping_id = ping_id; 92 array->entries[index].ping_id = ping_id;
90 return ping_id; 93 return ping_id;
@@ -100,22 +103,27 @@ uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length)
100 */ 103 */
101int ping_array_check(uint8_t *data, uint32_t length, Ping_Array *array, uint64_t ping_id) 104int ping_array_check(uint8_t *data, uint32_t length, Ping_Array *array, uint64_t ping_id)
102{ 105{
103 if (ping_id == 0) 106 if (ping_id == 0) {
104 return -1; 107 return -1;
108 }
105 109
106 uint32_t index = ping_id % array->total_size; 110 uint32_t index = ping_id % array->total_size;
107 111
108 if (array->entries[index].ping_id != ping_id) 112 if (array->entries[index].ping_id != ping_id) {
109 return -1; 113 return -1;
114 }
110 115
111 if (is_timeout(array->entries[index].time, array->timeout)) 116 if (is_timeout(array->entries[index].time, array->timeout)) {
112 return -1; 117 return -1;
118 }
113 119
114 if (array->entries[index].length > length) 120 if (array->entries[index].length > length) {
115 return -1; 121 return -1;
122 }
116 123
117 if (array->entries[index].data == NULL) 124 if (array->entries[index].data == NULL) {
118 return -1; 125 return -1;
126 }
119 127
120 memcpy(data, array->entries[index].data, array->entries[index].length); 128 memcpy(data, array->entries[index].data, array->entries[index].length);
121 uint32_t len = array->entries[index].length; 129 uint32_t len = array->entries[index].length;
@@ -132,13 +140,15 @@ int ping_array_check(uint8_t *data, uint32_t length, Ping_Array *array, uint64_t
132 */ 140 */
133int ping_array_init(Ping_Array *empty_array, uint32_t size, uint32_t timeout) 141int ping_array_init(Ping_Array *empty_array, uint32_t size, uint32_t timeout)
134{ 142{
135 if (size == 0 || timeout == 0 || empty_array == NULL) 143 if (size == 0 || timeout == 0 || empty_array == NULL) {
136 return -1; 144 return -1;
145 }
137 146
138 empty_array->entries = calloc(size, sizeof(Ping_Array_Entry)); 147 empty_array->entries = calloc(size, sizeof(Ping_Array_Entry));
139 148
140 if (empty_array->entries == NULL) 149 if (empty_array->entries == NULL) {
141 return -1; 150 return -1;
151 }
142 152
143 empty_array->last_deleted = empty_array->last_added = 0; 153 empty_array->last_deleted = empty_array->last_added = 0;
144 empty_array->total_size = size; 154 empty_array->total_size = size;