Convert sizeof foo to sizeof(foo).
[tinc] / src / top.c
index 40b8047..8d9ffb0 100644 (file)
--- a/src/top.c
+++ b/src/top.c
@@ -89,8 +89,8 @@ static bool update(int fd) {
        for list_each(nodestats_t, ns, &node_list)
                ns->known = false;
 
-       while(recvline(fd, line, sizeof line)) {
-               int n = sscanf(line, "%d %d %s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes);
+       while(recvline(fd, line, sizeof(line))) {
+               int n = sscanf(line, "%d %d %4095s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes);
 
                if(n == 2)
                        return true;
@@ -108,7 +108,7 @@ static bool update(int fd) {
                                found = ns;
                                break;
                        } else {
-                               found = xzalloc(sizeof *found);
+                               found = xzalloc(sizeof(*found));
                                found->name = xstrdup(name);
                                list_insert_before(&node_list, node, found);
                                changed = true;
@@ -117,7 +117,7 @@ static bool update(int fd) {
                }
 
                if(!found) {
-                       found = xzalloc(sizeof *found);
+                       found = xzalloc(sizeof(*found));
                        found->name = xstrdup(name);
                        list_insert_tail(&node_list, found);
                        changed = true;
@@ -158,40 +158,54 @@ static int cmpu64(uint64_t a, uint64_t b) {
 static int sortfunc(const void *a, const void *b) {
        const nodestats_t *na = *(const nodestats_t **)a;
        const nodestats_t *nb = *(const nodestats_t **)b;
+       int result;
+
        switch(sortmode) {
                case 1:
                        if(cumulative)
-                               return -cmpu64(na->in_packets, nb->in_packets) ?: na->i - nb->i;
+                               result = -cmpu64(na->in_packets, nb->in_packets);
                        else
-                               return -cmpfloat(na->in_packets_rate, nb->in_packets_rate) ?: na->i - nb->i;
+                               result = -cmpfloat(na->in_packets_rate, nb->in_packets_rate);
+                       break;
                case 2:
                        if(cumulative)
-                               return -cmpu64(na->in_bytes, nb->in_bytes) ?: na->i - nb->i;
+                               result = -cmpu64(na->in_bytes, nb->in_bytes);
                        else
-                               return -cmpfloat(na->in_bytes_rate, nb->in_bytes_rate) ?: na->i - nb->i;
+                               result = -cmpfloat(na->in_bytes_rate, nb->in_bytes_rate);
+                       break;
                case 3:
                        if(cumulative)
-                               return -cmpu64(na->out_packets, nb->out_packets) ?: na->i - nb->i;
+                               result = -cmpu64(na->out_packets, nb->out_packets);
                        else
-                               return -cmpfloat(na->out_packets_rate, nb->out_packets_rate) ?: na->i - nb->i;
+                               result = -cmpfloat(na->out_packets_rate, nb->out_packets_rate);
+                       break;
                case 4:
                        if(cumulative)
-                               return -cmpu64(na->out_bytes, nb->out_bytes) ?: na->i - nb->i;
+                               result = -cmpu64(na->out_bytes, nb->out_bytes);
                        else
-                               return -cmpfloat(na->out_bytes_rate, nb->out_bytes_rate) ?: na->i - nb->i;
+                               result = -cmpfloat(na->out_bytes_rate, nb->out_bytes_rate);
+                       break;
                case 5:
                        if(cumulative)
-                               return -cmpu64(na->in_packets + na->out_packets, nb->in_packets + nb->out_packets) ?: na->i - nb->i;
+                               result = -cmpu64(na->in_packets + na->out_packets, nb->in_packets + nb->out_packets);
                        else
-                               return -cmpfloat(na->in_packets_rate + na->out_packets_rate, nb->in_packets_rate + nb->out_packets_rate) ?: na->i - nb->i;
+                               result = -cmpfloat(na->in_packets_rate + na->out_packets_rate, nb->in_packets_rate + nb->out_packets_rate);
+                       break;
                case 6:
                        if(cumulative)
-                               return -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes) ?: na->i - nb->i;
+                               result = -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes);
                        else
-                               return -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate) ?: na->i - nb->i;
+                               result = -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate);
+                       break;
                default:
-                       return strcmp(na->name, nb->name) ?: na->i - nb->i;
+                       result = strcmp(na->name, nb->name);
+                       break;
        }
+
+       if(result)
+               return result;
+       else
+               return na->i - nb->i;
 }
 
 static void redraw(void) {
@@ -206,7 +220,7 @@ static void redraw(void) {
        static int n = 0;
        if(changed) {
                n = 0;
-               sorted = xrealloc(sorted, node_list.count * sizeof *sorted);
+               sorted = xrealloc(sorted, node_list.count * sizeof(*sorted));
                for list_each(nodestats_t, ns, &node_list)
                        sorted[n++] = ns;
                changed = false;
@@ -216,7 +230,7 @@ static void redraw(void) {
                sorted[i]->i = i;
 
        if(sorted)
-               qsort(sorted, n, sizeof *sorted, sortfunc);
+               qsort(sorted, n, sizeof(*sorted), sortfunc);
 
        for(int i = 0, row = 3; i < n; i++, row++) {
                nodestats_t *node = sorted[i];