Fixed adding message to data list before receiving messages
This commit is contained in:
parent
fd623ee484
commit
fae758e4dd
38
src/node.c
38
src/node.c
@ -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 the data list has never been used, or is empty ( same thing )
|
||||||
if (data_list == NULL) {
|
if (data_list == NULL) {
|
||||||
data_list = (list*) malloc(sizeof(struct list));
|
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;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
// Copy data
|
// Copy data
|
||||||
|
Loading…
Reference in New Issue
Block a user