diff --git a/list_movers.c b/list_movers.c index 18b9cab..12c220b 100644 --- a/list_movers.c +++ b/list_movers.c @@ -6,13 +6,19 @@ int ListCount(LIST *list) { } void *ListFirst(LIST *list) { - list->current = list->head; - return list->current->data; -} + if (list->size != 0) { + list->current = list->head; + return list->current->data; + } + return NULL; +} void *ListLast(LIST *list) { - list->current = list->tail; - return list->current->data; + if (list->size != 0) { + list->current = list->tail; + return list->current->data; + } + return NULL; } void *ListNext(LIST *list) { diff --git a/main.c b/main.c index bd73135..4bdd83f 100644 --- a/main.c +++ b/main.c @@ -69,11 +69,15 @@ void *output(void *arg) { char msg[30]; while (1) { pthread_mutex_lock(&receivemut); - ListFirst(receivelist); - strcpy(msg, ListCurr(receivelist)); - ListRemove(receivelist); + if (ListCount(receivelist) != 0) { + ListFirst(receivelist); + strcpy(msg, ListCurr(receivelist)); + ListRemove(receivelist); + } pthread_mutex_unlock(&receivemut); - printf("%s\n", msg); + if (ListCount(receivelist) != 0) { + printf("%s\n", msg); + } } return 0;