From 96cf02139c7a0a344f194c95c8d3a64168e45c6b Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Wed, 01 Jun 2022 05:06:10 +0000
Subject: [PATCH] Compiler optimisations breaking things

---
 slist.c |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/slist.c b/slist.c
index db2e935..971685f 100644
--- a/slist.c
+++ b/slist.c
@@ -115,9 +115,9 @@
 
 int comp_times(struct dns_list* a, struct dns_list* b)
 {
-    if (a->errors != b->errors) {
-        return a->errors > b->errors;
-    } else if (a->time.tv_sec == b->time.tv_sec) {
+	if (a->errors != b->errors) {
+		return a->errors > b->errors;
+	} else if (a->time.tv_sec == b->time.tv_sec) {
 		if (a->time.tv_nsec >= b->time.tv_nsec)
 			return 1;
 		else
@@ -130,11 +130,23 @@
 
 int print_servers(struct dns_list* head)
 {
+    struct dns_list* curr = head;
 	printf("%-16s | %-11s | %s\n", "Server", "Time", "Errors");
-	while (head) {
-		printf("%-16s | %ld.%09ld | %d\n", head->server, head->time.tv_sec,
-		       head->time.tv_nsec, head->errors);
-		head = head->next;
+	while (curr) {
+        if (curr->errors != -1) {
+            printf("%-16s | %ld.%09ld | %d\n", curr->server, curr->time.tv_sec,
+                   curr->time.tv_nsec, curr->errors);
+        }
+        curr = curr->next;
 	}
+    fflush(stdout);
+    curr = head;
+    if (head->errors == -1) {
+        printf("The following servers were unreachable:\n");
+        while (curr && curr->errors == -1) {
+            printf("%s\n", curr->server);
+            curr = curr->next;
+        }
+    }
 	return 0;
 }

--
Gitblit v1.10.0