Fixed adding message to data list before receiving messages

This commit is contained in:
n07070 2020-04-28 19:51:53 +02:00
parent fd623ee484
commit fae758e4dd
1 changed files with 22 additions and 16 deletions

View File

@ -229,23 +229,29 @@ int add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
// If the data list has never been used, or is empty ( same thing )
if (data_list == NULL) {
data_list = (list*) malloc(sizeof(struct list));
list *tmp = data_list;
// We create the next node of the linked list.
tmp->data = (void *) message;
tmp->next = NULL;
} else {
// we move until the last element of the dala_list,
// and add or data there.
// We use a temporary address to avoid writing to the static list.
// Seems weird but ok.
list *tmp = data_list;
while(tmp->next != NULL){
tmp = tmp->next;
}
// We create the next node of the linked list.
list * new_node = malloc(sizeof(struct list));
new_node->data = (void *) message;
// Adding the message to the list.
tmp->next = (void *) new_node;
}
// we move until the last element of the dala_list,
// and add or data there.
// We use a temporary address to avoid writing to the static list.
// Seems weird but ok.
list *tmp = data_list;
while(tmp->next != NULL){
tmp = tmp->next;
}
// We create the next node of the linked list.
list * new_node = malloc(sizeof(struct list));
new_node->data = (void *) message;
// Adding the message to the list.
tmp->next = (void *) new_node;
return 1;
} else {
// Copy data